From c9b48a27303739e92c12f926e3390ae505bd2563 Mon Sep 17 00:00:00 2001 From: ChairC <974833488@qq.com> Date: Wed, 29 May 2024 19:42:28 +0800 Subject: [PATCH] Add: Add Evaluation in README. --- README.md | 33 +++++++++++++++++++++++++++++++-- README_zh.md | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3b729c8..afcf4ba 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/README_zh.md b/README_zh.md index 9d04fd1..c8528cf 100644 --- a/README_zh.md +++ b/README_zh.md @@ -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的编号 | + -未完待续 ### 关于引用