diff --git a/.gitignore b/.gitignore index 0ffc9575a2d120e1cfad342dedb833397cdb99bc..742b4519a237e22b6c4a6352873c58a4c8166e50 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ */trained_ddpm root experiments -trainer/__pycache__ \ No newline at end of file +.ipynb_checkpoints +trainer/__pycache__ diff --git a/.ipynb_checkpoints/experiment_creator-checkpoint.ipynb b/.ipynb_checkpoints/experiment_creator-checkpoint.ipynb deleted file mode 100644 index 2e35c4ee2b0852f0c14234c07a8669da508e5f5b..0000000000000000000000000000000000000000 --- a/.ipynb_checkpoints/experiment_creator-checkpoint.ipynb +++ /dev/null @@ -1,189 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [], - "source": [ - "from trainer.train import *\n", - "from dataloader.load import *\n", - "from models.Framework import *\n", - "from models.unet_unconditional_diffusion import *\n", - "import torch \n", - "from torch import nn \n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Prepare experiment\n", - "1. Adapt settings below (for data path, only use absolute paths!!)\n", - "2. run both cells of the notebook, this creates a folder containing the json setting files \n", - "2. put the folder on the HPC\n", - "3. the following command starts the training `python main.py train \"<absolute path of folder in hpc>\"` add it to the batch file " - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "import torch \n", - "\n", - "#path to store, path to load data , path to checkpoint \n", - "\n", - "#basic settings:\n", - "learning_rate = 0.0001\n", - "batchsize = 8\n", - "datapath = \"/work/lect0100/lhq_256\"\n", - "checkpoint_path = None #when training from checkpoint\n", - "experimentname = \"/Users/gonzalo/Desktop/testing/\" + \"test1\" #always change experiment name! \n", - "epochs = 20\n", - "diffusion_steps = 25\n", - "image_size = 64\n", - "channels = 3\n", - "store_iter = 5\n", - "optimizername = \"torch.optim.AdamW\"\n", - "name_appendix = 'DM_bottleneck'# id for WANDB\n", - "\n", - "#advanced settings: change directly in dictionary \n", - "meta_setting = dict(modelname = \"UNet_Unconditional_Diffusion_Bottleneck_Variant\",\n", - " dataset = \"UnconditionalDataset\",\n", - " framework = \"DDPM\",\n", - " trainloop_function = \"ddpm_trainer\",\n", - " batchsize = batchsize,\n", - " )\n", - "\n", - "\n", - "dataset_setting = dict(fpath = datapath,\n", - " img_size = image_size,\n", - " frac =0.8,\n", - " skip_first_n = 0,\n", - " ext = \".png\",\n", - " transform=True\n", - " )\n", - "\n", - "\n", - "model_setting = dict( channels_in=channels, \n", - " channels_out =channels , \n", - " activation='relu', # activation function. Options: {'relu', 'leakyrelu', 'selu', 'gelu', 'silu'/'swish'}\n", - " weight_init='he', # weight initialization. Options: {'he', 'torch'}\n", - " projection_features=64, # number of image features after first convolution layer\n", - " time_dim=batchsize, #dont chnage!!!\n", - " time_channels=diffusion_steps, # number of time channels #TODO same as diffusion steps? \n", - " num_stages=4, # number of stages in contracting/expansive path\n", - " stage_list=None, # specify number of features produced by stages\n", - " num_blocks=1, # number of ConvResBlock in each contracting/expansive path\n", - " num_groupnorm_groups=32, # number of groups used in Group Normalization inside a ConvResBlock\n", - " dropout=0.1, # drop-out to be applied inside a ConvResBlock\n", - " attention_list=None, # specify MHA pattern across stages\n", - " num_attention_heads=1,\n", - " )\n", - "\n", - "\n", - "framework_setting = dict(\n", - " diffusion_steps = diffusion_steps, # dont change!!\n", - " out_shape = (channels,image_size,image_size), # dont change!!\n", - " noise_schedule = 'linear', \n", - " beta_1 = 1e-4, \n", - " beta_T = 0.02,\n", - " alpha_bar_lower_bound = 0.9,\n", - " var_schedule = 'same', \n", - " kl_loss = 'simplified', \n", - " recon_loss = 'none',\n", - " \n", - " )\n", - "\n", - "\n", - "training_setting = dict(\n", - " epochs = epochs,\n", - " store_iter = store_iter,\n", - " eval_iter = 3,\n", - " optimizer_class=optimizername, \n", - " optimizer_params=dict(lr=learning_rate), # don't change!\n", - " scheduler_class= None, \n", - " scheduler_params=None,\n", - " last_epoch=-1,\n", - " learning_rate = learning_rate,\n", - " lr_schedule = False,\n", - " verbose = True,\n", - " name_appendix=name_appendix,\n", - " checkpoint_path= checkpoint_path,\n", - " )" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "path already exists, pick a new name!\n", - "break\n" - ] - } - ], - "source": [ - "import os\n", - "import json\n", - "f = experimentname\n", - "if os.path.exists(f):\n", - " print(\"path already exists, pick a new name!\")\n", - " print(\"break\")\n", - "else:\n", - " print(\"create folder\")\n", - " os.mkdir(f)\n", - " print(\"folder created \")\n", - " with open(f+\"/meta_setting.json\",\"w+\") as fp:\n", - " json.dump(meta_setting,fp)\n", - "\n", - " with open(f+\"/dataset_setting.json\",\"w+\") as fp:\n", - " json.dump(dataset_setting,fp)\n", - " \n", - " with open(f+\"/model_setting.json\",\"w+\") as fp:\n", - " json.dump(model_setting,fp)\n", - " \n", - " with open(f+\"/framework_setting.json\",\"w+\") as fp:\n", - " json.dump(framework_setting,fp)\n", - "\n", - " with open(f+\"/training_setting.json\",\"w+\") as fp:\n", - " json.dump(training_setting,fp)\n", - "\n", - " print(\"stored json files in folder\")\n", - " print(meta_setting)\n", - " print(dataset_setting)\n", - " print(model_setting)\n", - " print(framework_setting)\n", - " print(training_setting)\n", - " " - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3.9 (pytorch)", - "language": "python", - "name": "pytorch" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.16" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}