Skip to content

Commit

Permalink
Add: Add Evaluation in README.
Browse files Browse the repository at this point in the history
  • Loading branch information
chairc committed May 29, 2024
1 parent 464b4f7 commit c9b48a2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,38 @@ Of course, based on the 64×64 U-Net model, we generate 160×160 `NEU-DET` image
![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)


### Deployment
### Evaluation

To be continued.
1. During the data preparation stage, use `generate.py` to create the dataset. The amount and size of the generated dataset should be similar to the training set (**Note**: The training set required for evaluation should be resized to the size used during training, which is the `image_size`. For example, if the training set path is `/your/path/datasets/landscape` with an image size of **256**, and the generated set path is `/your/path/generate/landscape` with a size of 64, use the `resize` method to convert the images in the training set path to **64**. The new evaluation training set path will be `/your/new/path/datasets/landscape`).

2. Open the `FID_calculator.py` or `FID_calculator_plus.py` file for evaluation. `FID_calculator.py` is for **simple evaluation**; `FID_calculator_plus.py` is for **custom evaluation**, allowing various parameter settings.

3. If using `FID_calculator.py`, set `generated_image_folder` to `/your/path/generate/landscape` and `dataset_image_folder` to `/your/new/path/datasets/landscape`. **Right-click to run**.

4. If using `FID_calculator_plus.py`, set the necessary parameters such as `path`, `--batch_size`, `--num-workers`, `--dims`, `--save_stats`, and `--use_gpu`. If no parameters are set, the default settings will be used. There are two methods for setting parameters. One is to directly set the `parser` in the `if __name__ == "__main__":` block of the `FID_calculator_plus.py` file. The other is to enter the following command in the console under the `/your/path/Defect-Diffiusion-Model/tools` directory:

**For evaluation only**

```bash
python FID_calculator_plus.py /your/path/generate/landscape /your/new/path/datasets/landscape --batch_size 8 --num-workers 2 --dims 2048 --use_gpu 0
```

**To generate npz archives** (**generally not needed**)

```bash
python FID_calculator_plus.py /your/input/path /your/output/path --save_stats
```

#### Evaluation Parameters

| **Parameter Name** | Usage | Parameter Type | Explanation |
| ------------------ | --------------------------- | :------------: | ------------------------------------------------------------ |
| path | Path | str | Input two paths: the generated set path and the training set path in evaluation mode; input path and output path in npz mode |
| --batch_size | Training batch size | int | Size of each training batch |
| --num_workers | Number of loading processes | int | Number of subprocesses used for data loading. It consumes a large amount of CPU and memory but can speed up training |
| --dims | Dimensions | str | The dimensions of the Inception features to use |
| --save_stats | Save stats | str | Generate npz archives from the sample directory |
| --use_gpu | Specify GPU | int | Generally used to set the specific GPU for training, input the GPU number |

### About Citation

Expand Down
35 changes: 33 additions & 2 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,40 @@ Integrated Design Diffusion Model

![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)

### 部署
### 评估

1. 数据准备阶段,使用`generate.py`生成数据集,数据集生成量应该与训练集的数量、尺寸相似(**注意**:评估时所需要的训练集应为进行了`resize`后的结果,即为训练时的`image_size`大小。例如,训练集的路径为`/your/path/datasets/landscape`,图片尺寸为**256**;生成集的路径为`/your/path/generate/landscape`,尺寸为64,使用`resize`方法将训练集路径中的图片转为**64**,此时新的评估用训练集路径为`/your/new/path/datasets/landscape`)。

2. 打开`FID_calculator.py``FID_calculator_plus.py`文件进行评估。`FID_calculator.py`**简单评估**`FID_calculator_plus.py`**自定义评估**,可设置多种参数。

3. 若打开文件为`FID_calculator.py`,设置`generated_image_folder``/your/path/generate/landscape``dataset_image_folder``/your/new/path/datasets/landscape`**右键运行即可**

4. 若打开文件为`FID_calculator_plus.py`,设置必要参数,例如`path``--batch_size``--num-workers``--dims``--save_stats``--use_gpu`参数,若不设置参数则使用默认设置。我们有两种参数设置方法,其一是直接对`FID_calculator_plus.py`文件`if __name__ == "__main__":`中的`parser`进行设置;其二是在控制台在`/your/path/Defect-Diffiusion-Model/tools`路径下输入以下命令:

**仅进行评估操作**

```bash
python FID_calculator_plus.py /your/path/generate/landscape /your/new/path/datasets/landscape --batch_size 8 --num-workers 2 --dims 2048 --use_gpu 0
```

**生成npz存档****一般用不到**

```bash
python FID_calculator_plus.py /your/input/path /your/output/path --save_stats
```

#### 评估参数

| **参数名称** | 参数使用方法 | 参数类型 | 参数解释 |
| ------------- | ----------------- | :------: | ------------------------------------------------------------ |
| path | 路径 | str | 输入2个路径,评估模式下为生成集路径和训练集路径;npz模式下为输入路径和输出路径 |
| --batch_size | 训练批次 | int | 训练批次大小 |
| --num_workers | 加载进程数量 | int | 用于数据加载的子进程数量,大量占用CPU和内存,但可以加快训练速度 |
| --dims | 维度 | str | 要使用的 Inception 功能的维度 |
| --save_stats | 保存存档 | str | 从样本目录生成 npz 存档 |
| --use_gpu | 设置运行指定的GPU | int | 一般训练中设置指定的运行GPU,输入为GPU的编号 |


未完待续

### 关于引用

Expand Down

0 comments on commit c9b48a2

Please sign in to comment.