Skip to content

Commit

Permalink
Update: Modify test error.
Browse files Browse the repository at this point in the history
  • Loading branch information
chairc committed Sep 22, 2023
1 parent c749bb7 commit 4b43d32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,32 @@ We named this project IDDM: Industrial Defect Diffusion Model. It aims to reprod

#### Normal Training

1. Take the `landscape` dataset as an example and place the dataset files in the `datasets` folder. The overall path of the dataset should be `/your/path/datasets/landscape`, and the image files should be located at `/your/path/datasets/landscape/*.jpg`.
1. Take the `landscape` dataset as an example and place the dataset files in the `datasets` folder. The overall path of the dataset should be `/your/path/datasets/landscape`, the images path should be `/your/path/datasets/landscape/images`, and the image files should be located at `/your/path/datasets/landscape/images/*.jpg`.

2. Open the `train.py` file and locate the `--dataset_path` parameter. Modify the path in the parameter to the overall dataset path, for example, `/your/path/datasets/landscape`.

3. Set the necessary parameters such as `--sample`, `--conditional`, `--run_name`, `--epochs`, `--batch_size`, `--image_size`, `--result_path`, etc. If no parameters are set, the default settings will be used. There are two ways to set the parameters: directly modify the `parser` in the `if __name__ == "__main__":` section of the `train.py` file (**WE RECOMMEND THIS WAY**), or run the following command in the terminal at the `/your/path/Defect-Diffusion-Model/tools` directory:
**Conditional Training Command**

```bash
python train.py --sample 'ddpm' --conditional True --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --sample ddpm --conditional True --run_name df --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path /your/dataset/path --result_path /your/save/path
```
**Unconditional Training Command**

```bash
python train.py --sample 'ddpm' --conditional False --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --sample ddpm --conditional False --run_name df --epochs 300 --batch_size 16 --image_size 64 --dataset_path /your/dataset/path --result_path /your/save/path
```
4. Wait for the training to complete.
5. If the training is interrupted due to any reason, you can resume it by setting `--resume` to `True` in the `train.py` file, specifying the epoch number where the interruption occurred, providing the folder name of the interrupted training (`run_name`), and running the file again. Alternatively, you can use the following command to resume the training:
**Conditional Resume Training Command**

```bash
python train.py --resume True --start_epoch 10 --load_model_dir 'df' --sample 'ddpm' --conditional True --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --resume True --start_epoch 10 --load_model_dir df --sample ddpm --conditional True --run_name df --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path /your/dataset/path --result_path /your/save/path
```
**Unconditional Resume Training Command**

```bash
python train.py --resume True --start_epoch 10 --load_model_dir 'df' --sample 'ddpm' --conditional False --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --resume True --start_epoch 10 --load_model_dir df --sample ddpm --conditional False --run_name df --epochs 300 --batch_size 16 --image_size 64 --dataset_path /your/dataset/path --result_path /your/save/path
```
#### Distributed Training

Expand All @@ -144,13 +144,13 @@ We named this project IDDM: Industrial Defect Diffusion Model. It aims to reprod
**Conditional Distributed Training Command**

```bash
python train.py --sample 'ddpm' --conditional True --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path '/your/dataset/path' --result_path '/your/save/path' --distributed True --main_gpu 0 --world_size 2
python train.py --sample ddpm --conditional True --run_name df --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path /your/dataset/path --result_path /your/save/path --distributed True --main_gpu 0 --world_size 2
```

**Unconditional Distributed Training Command**

```bash
python train.py --sample 'ddpm' --conditional False --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --dataset_path '/your/dataset/path' --result_path '/your/save/path' --distributed True --main_gpu 0 --world_size 2
python train.py --sample ddpm --conditional False --run_name df --epochs 300 --batch_size 16 --image_size 64 --dataset_path /your/dataset/path --result_path /your/save/path --distributed True --main_gpu 0 --world_size 2
```

4. Wait for the training to complete. Interrupt recovery is the same as basic training.
Expand All @@ -175,7 +175,7 @@ We named this project IDDM: Industrial Defect Diffusion Model. It aims to reprod
| --fp16 | | Half precision training | bool | Enable half precision training. It effectively reduces GPU memory usage but may affect training accuracy and results |
| --optim | | Optimizer | str | Optimizer selection. Currently supports Adam and AdamW |
| --act | | Activation function | str | Activation function selection. Currently supports gelu, silu, relu, relu6 and lrelu |
| --lr | | Learning rate | int | Initial learning rate. Currently only supports linear learning rate |
| --lr | | Learning rate | float | Initial learning rate. Currently only supports linear learning rate |
| --lr_func | | Learning rate schedule | str | Setting learning rate schedule, currently supporting linear, cosine, and warmup_cosine. |
| --result_path | | Save path | str | Path to save the training results |
| --save_model_interval | | Save model after each training | bool | Whether to save the model after each training iteration for model selection based on visualization |
Expand All @@ -200,13 +200,13 @@ We named this project IDDM: Industrial Defect Diffusion Model. It aims to reprod
**Conditional Generation Command**

```bash
python generate.py --conditional True --generate_name 'df' --num_images 8 --num_classes 10 --class_name 0 --image_size 64 --weight_path '/your/path/weight/model.pt'
python generate.py --conditional True --generate_name df --num_images 8 --num_classes 10 --class_name 0 --image_size 64 --weight_path /your/path/weight/model.pt
```

**Unconditional Generation Command**

```bash
python generate.py --conditional False --generate_name 'df' --num_images 8 --image_size 64 --weight_path '/your/path/weight/model.pt'
python generate.py --conditional False --generate_name df --num_images 8 --image_size 64 --weight_path /your/path/weight/model.pt
```

3. Wait for the generation process to complete.
Expand Down
22 changes: 11 additions & 11 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

设置`--result_path`参数为`/你的/本地/或/远程服务器/文件/地址/results`

设置`--num_classes`参数为`10`,这是你的类别总数;
设置`--num_classes`参数为`10`,这是你的类别总数

设置更多参数(自定义),如果报`CUDA out of memory`错误,将`--batch_size``--num_workers`调小;

Expand All @@ -105,32 +105,32 @@

#### 普通训练

1.`landscape`数据集为例,将数据集文件放入`datasets`文件夹中,该数据集的总路径如下`/your/path/datasets/landscape`,数据集图片路径如下`/your/path/datasets/landscape/*.jpg`
1.`landscape`数据集为例,将数据集文件放入`datasets`文件夹中,该数据集的总路径如下`/your/path/datasets/landscape`图片存放在`/your/path/datasets/landscape/images`数据集图片路径如下`/your/path/datasets/landscape/images/*.jpg`

2. 打开`train.py`文件,找到`--dataset_path`参数,将参数中的路径修改为数据集的总路径,例如`/your/path/datasets/landscape`

3. 设置必要参数,例如`--sample``--conditional``--run_name``--epochs``--batch_size``--image_size``--result_path`等参数,若不设置参数则使用默认设置。我们有两种参数设置方法,其一是直接对`train.py`文件`if __name__ == "__main__":`中的`parser`进行设置(**我们推荐这种方式**);其二是在控制台在`/your/path/Defect-Diffiusion-Model/tools`路径下输入以下命令:
**有条件训练命令**

```bash
python train.py --sample 'ddpm' --conditional True --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --sample ddpm --conditional True --run_name df --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path /your/dataset/path --result_path /your/save/path
```
**无条件训练命令**

```bash
python train.py --sample 'ddpm' --conditional False --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --sample ddpm --conditional False --run_name df --epochs 300 --batch_size 16 --image_size 64 --dataset_path /your/dataset/path --result_path /your/save/path
```
4. 等待训练即可
5. 若因异常原因中断训练,我们可以在`train.py`文件,首先将`--resume`设置为`True`,其次设置异常中断的迭代编号,再写入该次训练的所在文件夹(run_name),最后运行文件即可。也可以使用如下命令进行恢复:
**有条件恢复训练命令**

```bash
python train.py --resume True --start_epoch 10 --load_model_dir 'df' --sample 'ddpm' --conditional True --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --resume True --start_epoch 10 --load_model_dir df --sample ddpm --conditional True --run_name df --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path /your/dataset/path --result_path /your/save/path
```
**无条件恢复训练命令**

```bash
python train.py --resume True --start_epoch 10 --load_model_dir 'df' --sample 'ddpm' --conditional False --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --dataset_path '/your/dataset/path' --result_path '/your/save/path'
python train.py --resume True --start_epoch 10 --load_model_dir df --sample ddpm --conditional False --run_name df --epochs 300 --batch_size 16 --image_size 64 --dataset_path /your/dataset/path --result_path /your/save/path
```

#### 分布式训练
Expand All @@ -144,13 +144,13 @@
**有条件训练命令**

```bash
python train.py --sample 'ddpm' --conditional True --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path '/your/dataset/path' --result_path '/your/save/path' --distributed True --main_gpu 0 --world_size 2
python train.py --sample ddpm --conditional True --run_name df --epochs 300 --batch_size 16 --image_size 64 --num_classes 10 --dataset_path /your/dataset/path --result_path /your/save/path --distributed True --main_gpu 0 --world_size 2
```

**无条件训练命令**

```bash
python train.py --sample 'ddpm' --conditional False --run_name 'df' --epochs 300 --batch_size 16 --image_size 64 --dataset_path '/your/dataset/path' --result_path '/your/save/path' --distributed True --main_gpu 0 --world_size 2
python train.py --sample ddpm --conditional False --run_name df --epochs 300 --batch_size 16 --image_size 64 --dataset_path /your/dataset/path --result_path /your/save/path --distributed True --main_gpu 0 --world_size 2
```

3. 等待训练即可,中断恢复同基本训练一致。
Expand Down Expand Up @@ -178,7 +178,7 @@
| --fp16 | | 半精度训练 | bool | 开启半精度训练,有效减少显存使用,但无法保证训练精度和训练结果 |
| --optim | | 优化器 | str | 优化器选择,目前支持adam和adamw |
| --act | | 激活函数 | str | 激活函数选择,目前支持gelu、silu、relu、relu6和lrelu |
| --lr | | 学习率 | int | 初始化学习率,目前仅支持线性学习率 |
| --lr | | 学习率 | float | 初始化学习率,目前仅支持线性学习率 |
| --lr_func | | 学习率方法 | str | 设置学习率方法,当前支持linear、cosine和warmup_cosine |
| --result_path | | 保存路径 | str | 保存路径 |
| --save_model_interval | | 是否每次训练储存 | bool | 是否每次训练储存,根据可视化生成样本信息筛选模型 |
Expand All @@ -205,13 +205,13 @@
**有条件生成命令**

```bash
python generate.py --conditional True --generate_name 'df' --num_images 8 --num_classes 10 --class_name 0 --image_size 64 --weight_path '/your/path/weight/model.pt'
python generate.py --conditional True --generate_name df --num_images 8 --num_classes 10 --class_name 0 --image_size 64 --weight_path /your/path/weight/model.pt
```

**无条件生成命令**

```bash
python generate.py --conditional False --generate_name 'df' --num_images 8 --image_size 64 --weight_path '/your/path/weight/model.pt'
python generate.py --conditional False --generate_name df --num_images 8 --image_size 64 --weight_path /your/path/weight/model.pt
```

3. 等待生成即可
Expand Down

0 comments on commit 4b43d32

Please sign in to comment.