Skip to content

Commit 0bb8614

Browse files
committed
docs: Update README.
1 parent 9e2d28b commit 0bb8614

7 files changed

Lines changed: 83 additions & 40 deletions

File tree

docs/en-US/03_generation.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
1. Open the `generate.py` file and locate the `--weight_path` parameter. Modify the path in the parameter to the path of your model weights, for example `/your/path/weight/model.pt`.
88

9-
2. Set the necessary parameters such as `--conditional`, `--generate_name`, `--num_images`, `--num_classes`(**No need to set for models after version 1.1.4**), `--class_name`, `--image_size`, `--result_path`, etc. If no parameters are set, the default settings will be used. There are two ways to set the parameters: one is to directly modify the `parser` in the `if __name__ == "__main__":` section of the `generate.py` file, and the other is to use the following commands in the console while in the `/your/path/Defect-Diffusion-Model/tools` directory:
9+
2. Set the necessary parameters such as `--conditional`,`--latent`, `--generate_name`, `--num_images`, `--num_classes`(**No need to set for models after version 1.1.4**), `--class_name`, `--image_size`, `--result_path`, etc. If no parameters are set, the default settings will be used. There are two ways to set the parameters: one is to directly modify the `parser` in the `if __name__ == "__main__":` section of the `generate.py` file, and the other is to use the following commands in the console while in the `/your/path/Defect-Diffusion-Model/tools` directory:
1010

1111
**Conditional Generation Command (version > 1.1.1)**
1212

@@ -32,6 +32,18 @@
3232
python generate.py --generate_name df --num_images 8 --image_size 64 --weight_path /your/path/weight/model.pt --sample ddpm --network unet --act gelu
3333
```
3434

35+
**Conditional Latent Generation Command (version > 1.2.0)**
36+
37+
```bash
38+
python generate.py --conditional --latent --generate_name df --num_images 8 --class_name 0 --image_size 64 --weight_path /your/path/weight/model.pt --sample ddim --autoencoder_ckpt /your/path/weight/autoencoder_model.pt
39+
```
40+
41+
**Unconditional Latent Generation Command (version > 1.2.0)**
42+
43+
```bash
44+
python generate.py --latent --generate_name df --num_images 8 --image_size 64 --weight_path /your/path/weight/model.pt --sample ddim --autoencoder_ckpt /your/path/weight/autoencoder_model.pt
45+
```
46+
3547
3. Wait for the generation process to complete.
3648

3749
##### Python generation
@@ -65,20 +77,22 @@ for i in range(num_images):
6577
>
6678
> `--num_classes` do not need to set for models after **version 1.1.4**
6779
68-
| Parameter Name | Conditional | Usage | Type | Description |
69-
| --------------- | :---------: | ------------------------------- | :--: | ------------------------------------------------------------ |
70-
| --conditional | | Enable conditional generation | bool | If enabled, allows custom configuration, such as modifying classes or classifier-free guidance interpolation weights |
71-
| --generate_name | | File name | str | File name to initialize the model for saving purposes |
72-
| --image_size | | Input image size | int | Size of input images, adaptive input/output size. if class name is -1 and conditional is True, the model would output one image per class. |
73-
| --image_format | | Generated image format | str | Generated image format, jpg/png/jpeg. Recommend to use png for better generation quality. |
74-
| --num_images | | Number of generated images | int | Number of images to generate |
75-
| --weight_path | | Path to model weights | str | Path to the model weights file, required for network generation |
76-
| --result_path | | Save path | str | Path to save the generated images |
77-
| --use_gpu | | Set the use GPU | int | Set the use GPU in generate, input is GPU's id |
78-
| --sample | | Sampling method | str | Set the sampling method type, currently supporting DDPM and DDIM. **(No need to set for models after version 1.1.1)** |
79-
| --network | | Training network | str | Set the training network, currently supporting UNet, CSPDarkUNet. **(No need to set for models after version 1.1.1)** |
80-
| --act | | Activation function | str | Activation function selection. Currently supports gelu, silu, relu, relu6 and lrelu. If you do not set the same activation function as the model, mosaic phenomenon will occur. **(No need to set for models after version 1.1.1)** |
81-
| --num_classes || Number of classes | int | Number of classes for classification **(No need to set for models after version 1.1.1)** |
82-
| --class_name || Class name | int | Index of the class to generate images. if class name is `-1`, the model would output one image per class. |
83-
| --cfg_scale || Classifier-free guidance weight | int | Weight for classifier-free guidance interpolation, for better generation model performance |
80+
| Parameter Name | Conditional | Usage | Type | Description |
81+
| ------------------ | :---------: | ------------------------------- | :--: | ------------------------------------------------------------ |
82+
| --conditional | | Enable conditional generation | bool | If enabled, allows custom configuration, such as modifying classes or classifier-free guidance interpolation weights. |
83+
| --generate_name | | File name | str | File name to initialize the model for saving purposes. |
84+
| --latent | | Enable latent diffusion model | bool | If enabled, the model will use latent diffusion. |
85+
| --image_size | | Input image size | int | Size of input images, adaptive input/output size. if class name is -1 and conditional is True, the model would output one image per class. |
86+
| --image_format | | Generated image format | str | Generated image format, jpg/png/jpeg. Recommend to use png for better generation quality. |
87+
| --num_images | | Number of generated images | int | Number of images to generate. |
88+
| --weight_path | | Path to model weights | str | Path to the model weights file, required for network generation. |
89+
| --autoencoder_ckpt | | VAE model weight path | str | VAE model weight path. |
90+
| --result_path | | Save path | str | Path to save the generated images. |
91+
| --use_gpu | | Set the use GPU | int | Set the use GPU in generate, input is GPU's id. |
92+
| --sample | | Sampling method | str | Set the sampling method type, currently supporting DDPM and DDIM. **(No need to set for models after version 1.1.1)** |
93+
| --network | | Training network | str | Set the training network, currently supporting UNet, CSPDarkUNet. **(No need to set for models after version 1.1.1)** |
94+
| --act | | Activation function | str | Activation function selection. Currently supports gelu, silu, relu, relu6 and lrelu. If you do not set the same activation function as the model, mosaic phenomenon will occur. **(No need to set for models after version 1.1.1)** |
95+
| --num_classes || Number of classes | int | Number of classes for classification. **(No need to set for models after version 1.1.1)** |
96+
| --class_name || Class name | int | Index of the class to generate images. if class name is `-1`, the model would output one image per class. |
97+
| --cfg_scale || Classifier-free guidance weight | int | Weight for classifier-free guidance interpolation, for better generation model performance. |
8498

docs/en-US/04_results.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ Of course, based on the 64×64 U-Net model, we generate 160×160 `NEU-DET` image
4242

4343
![model_499_ema](../../assets/neu160_0.jpg)![model_499_ema](../../assets/neu160_1.jpg)![model_499_ema](../../assets/neu160_2.jpg)![model_499_ema](../../assets/neu160_3.jpg)![model_499_ema](../../assets/neu160_4.jpg)![model_499_ema](../../assets/neu160_5.jpg)
4444

45+
46+
47+
#### Use latent model to generate NEU-DET images
48+
49+
![neu_latent_299_ema](../../assets/neu_latent_299_ema.png)

docs/en-US/06_model_list.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Coming soon :-)
2929

3030
##### Autoencoder Pre-trained Model
3131

32-
| Model Name | Latent | Datasets | Model Size | Download Link |
33-
| :-----------------------------: | :----: | :------: | :--------: | :-----------: |
32+
| Model Name | Latent | Datasets | Model Size | Download Link |
33+
| :-----------------------------: | :----: | :------: | :--------: | :----------------------------------------------------------: |
3434
| `neu-autoencoder-512-weight.pt` || NEU-DET | 512×512 | [Download](https://github.com/chairc/Integrated-Design-Diffusion-Model/releases/download/v1.2.0/neu-autoencoder-512-weight.pt) |
35+
| `voc-autoencoder-512-weight.pt` || VOC2012 | 512×512 | [Download](https://github.com/chairc/Integrated-Design-Diffusion-Model/releases/download/v1.2.1/voc-autoencoder-512-weight.pt) |

docs/zh-Hans/03_生成.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
1. 打开`generate.py`文件,找到`--weight_path`参数,将参数中的路径修改为模型权重路径,例如`/your/path/weight/model.pt`
88

9-
2. 设置必要参数,例如`--conditional``--generate_name``--num_images``--num_classes`**1.1.4版本后的模型可不用设置**),`--class_name``--image_size``--result_path`等参数,若不设置参数则使用默认设置。我们有两种参数设置方法,其一是直接对`generate.py`文件`if __name__ == "__main__":`中的`parser`进行设置;其二是在控制台在`/your/path/Defect-Diffiusion-Model/tools`路径下输入以下命令:
9+
2. 设置必要参数,例如`--conditional``--latent``--generate_name``--num_images``--num_classes`**1.1.4版本后的模型可不用设置**),`--class_name``--image_size``--result_path`等参数,若不设置参数则使用默认设置。我们有两种参数设置方法,其一是直接对`generate.py`文件`if __name__ == "__main__":`中的`parser`进行设置;其二是在控制台在`/your/path/Defect-Diffiusion-Model/tools`路径下输入以下命令:
1010
**有条件生成命令(1.1.1版本以上)**
1111

1212
```bash
@@ -31,6 +31,19 @@
3131
python generate.py --generate_name df --num_images 8 --image_size 64 --weight_path /your/path/weight/model.pt --sample ddpm --network unet --act gelu
3232
```
3333

34+
**有条件潜在生成命令(1.2.0版本及以上)**
35+
36+
```bash
37+
python generate.py --conditional --latent --generate_name df --num_images 8 --class_name 0 --image_size 64 --weight_path /your/path/weight/model.pt --sample ddim --autoencoder_ckpt /your/path/weight/autoencoder_model.pt
38+
```
39+
40+
**无条件潜在生成命令(1.2.0版本及以上)**
41+
42+
```bash
43+
python generate.py --latent --generate_name df --num_images 8 --image_size 64 --weight_path /your/path/weight/model.pt --sample ddim --autoencoder_ckpt /your/path/weight/autoencoder_model.pt
44+
```
45+
46+
3447
3. 等待生成即可
3548

3649
##### Python脚本生成
@@ -64,19 +77,21 @@ for i in range(num_images):
6477
>
6578
> `--num_classes`**1.1.4版本**后的模型可不用设置
6679
67-
| **参数名称** | 条件参数 | 参数使用方法 | 参数类型 | 参数解释 |
68-
| --------------- | :------: | -------------------------------- | :------: | ------------------------------------------------------------ |
69-
| --conditional | | 开启条件生成 | bool | 若开启可修改自定义配置,例如修改类别、classifier-free guidance插值权重 |
70-
| --generate_name | | 文件名称 | str | 初始化模型的文件名称,用于设置保存信息 |
71-
| --image_size | | 输入图像大小 | int | 输入图像大小,自适应输入输出尺寸。如果输入为-1并且开启条件生成为真,则模型为每类输出一张图片 |
72-
| --image_format | | 生成图片格式 | str | 生成图片格式,jpg/png/jpeg等。推荐使用png获取更好的生产质量 |
73-
| --num_images | | 生成图片个数 | int | 单次生成图片个数 |
74-
| --weight_path | | 权重路径 | str | 模型权重路径,网络生成需要加载文件 |
75-
| --result_path | | 保存路径 | str | 保存路径 |
76-
| --use_gpu | | 设置运行指定的GPU | int | 生成中设置指定的运行GPU,输入为GPU的编号 |
77-
| --sample | | 采样方式 | str | 设置采样器类别,当前支持ddpm,ddim(**1.1.1版本后的模型可不用设置**|
78-
| --network | | 训练网络 | str | 设置训练网络,当前支持UNet,CSPDarkUNet(**1.1.1版本后的模型可不用设置**|
79-
| --act | | 激活函数 | str | 激活函数选择,目前支持gelu、silu、relu、relu6和lrelu。如果不选择,会产生马赛克现象(**1.1.1版本后的模型可不用设置**|
80-
| --num_classes || 类别个数 | int | 类别个数,用于区分类别(**1.1.4版本后的模型可不用设置**|
81-
| --class_name || 类别名称 | int | 类别序号,用于对指定类别生成。如果输入为-1,则模型为每类输出一张图片 |
82-
| --cfg_scale || classifier-free guidance插值权重 | int | classifier-free guidance插值权重,用户更好生成模型效果 |
80+
| **参数名称** | 条件参数 | 参数使用方法 | 参数类型 | 参数解释 |
81+
| ------------------ | :------: | -------------------------------- | :------: | ------------------------------------------------------------ |
82+
| --conditional | | 开启条件生成 | bool | 若开启可修改自定义配置,例如修改类别、classifier-free guidance插值权重(**1.1.1版本后的模型可不用设置**|
83+
| --generate_name | | 文件名称 | str | 初始化模型的文件名称,用于设置保存信息 |
84+
| --latent | | 是否开启潜扩散训练 | bool | 若开启模型将进行潜扩散训练(**1.2.0版本新增**|
85+
| --image_size | | 输入图像大小 | int | 输入图像大小,自适应输入输出尺寸。如果输入为-1并且开启条件生成为真,则模型为每类输出一张图片 |
86+
| --image_format | | 生成图片格式 | str | 生成图片格式,jpg/png/jpeg等。推荐使用png获取更好的生产质量 |
87+
| --num_images | | 生成图片个数 | int | 单次生成图片个数 |
88+
| --weight_path | | 权重路径 | str | 模型权重路径,网络生成需要加载文件 |
89+
| --autoencoder_ckpt | | 变分自编码器权重路径 | str | 变分自编码器权重路径(**1.2.0版本新增**|
90+
| --result_path | | 保存路径 | str | 保存路径 |
91+
| --use_gpu | | 设置运行指定的GPU | int | 生成中设置指定的运行GPU,输入为GPU的编号 |
92+
| --sample | | 采样方式 | str | 设置采样器类别,当前支持ddpm,ddim(**1.1.1版本后的模型可不用设置**|
93+
| --network | | 训练网络 | str | 设置训练网络,当前支持UNet,CSPDarkUNet(**1.1.1版本后的模型可不用设置**|
94+
| --act | | 激活函数 | str | 激活函数选择,目前支持gelu、silu、relu、relu6和lrelu。如果不选择,会产生马赛克现象(**1.1.1版本后的模型可不用设置**|
95+
| --num_classes || 类别个数 | int | 类别个数,用于区分类别(**1.1.4版本后的模型可不用设置**|
96+
| --class_name || 类别名称 | int | 类别序号,用于对指定类别生成。如果输入为-1,则模型为每类输出一张图片 |
97+
| --cfg_scale || classifier-free guidance插值权重 | int | classifier-free guidance插值权重,用户更好生成模型效果 |

docs/zh-Hans/04_结果.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@
3838

3939
#### 基于64×64模型生成160×160(任意大尺寸)图像(仅限工业表面缺陷生成)
4040

41-
当然,我们根据64×64的基础模型,在`generate.py`文件中生成160×160的`NEU-DET`图片(单张输出,每张图片占用显存21GB)。**请注意这个**[[**issue**]](https://github.com/chairc/Integrated-Design-Diffusion-Model/issues/9#issuecomment-1886422210):如果是缺陷纹理那种图片,特征物不明显的直接生成大尺寸就不会有这些问题,例如NRSD、NEU数据集。如果是含有背景有特定明显特征的则需要超分或者resize提升尺寸,例如Cifar10、CelebA-HQ等。**如果实在需要大尺寸图像,在显存足够的情况下直接训练大像素图片**。详细图片如下:
41+
当然,我们根据64×64的基础模型,在`generate.py`文件中生成160×160的`NEU-DET`图片(单张输出,每张图片占用显存21GB,未使用`--latent`)。**请注意这个**[[**issue**]](https://github.com/chairc/Integrated-Design-Diffusion-Model/issues/9#issuecomment-1886422210):如果是缺陷纹理那种图片,特征物不明显的直接生成大尺寸就不会有这些问题,例如NRSD、NEU数据集。如果是含有背景有特定明显特征的则需要超分或者resize提升尺寸,例如Cifar10、CelebA-HQ等。**如果实在需要大尺寸图像,在显存足够的情况下直接训练大像素图片**。详细图片如下:
4242

4343
![model_499_ema](../../assets/neu160_0.jpg)![model_499_ema](../../assets/neu160_1.jpg)![model_499_ema](../../assets/neu160_2.jpg)![model_499_ema](../../assets/neu160_3.jpg)![model_499_ema](../../assets/neu160_4.jpg)![model_499_ema](../../assets/neu160_5.jpg)
4444

45+
46+
47+
#### 使用Latent方法生成NEU-DET图像
48+
49+
![neu_latent_299_ema](../../assets/neu_latent_299_ema.png)

0 commit comments

Comments
 (0)