diff --git a/README.md b/README.md index 87bbcb42cecf1..9a6944145be4c 100644 --- a/README.md +++ b/README.md @@ -1,43 +1,40 @@ -English | [简体中文](./README_cn.md) +简体中文 | [English](./README_en.md) # PaddleGAN -PaddleGAN is an development kit of Generative Adversarial Network based on PaddlePaddle. +PaddleGAN 是一个基于飞桨的生成对抗网络开发工具包. -### Image Translation +### 图片变换 ![](./docs/imgs/A2B.png) ![](./docs/imgs/B2A.png) -### Makeup shifter +### 妆容迁移 ![](./docs/imgs/makeup_shifter.png) -### Old video restore +### 老视频修复 ![](./docs/imgs/color_sr_peking.gif) -### Super resolution - +### 超分辨率 ![](./docs/imgs/sr_demo.png) -### Motion driving +### 动作驱动 ![](./docs/imgs/first_order.gif) -Features: +特性: -- Highly Flexible: +- 高度的灵活性: - Components are designed to be modular. Model architectures, as well as data -preprocess pipelines, can be easily customized with simple configuration -changes. + 模块化设计,解耦各个网络组件,开发者轻松搭建、试用各种检测模型及优化策略,快速得到高性能、定制化的算法。 -- Rich applications: +- 丰富的应用: - PaddleGAN provides rich of applications, such as image generation, image restore, image colorization, video interpolate, makeup shifter. + PaddleGAN 提供了非常多的应用,比如说图像生成,图像修复,图像上色,视频补帧,人脸妆容迁移等. -## Install +## 安装 -### 1. install paddlepaddle +### 1. 安装 paddlepaddle -PaddleGAN work with: +PaddleGAN 所需的版本: * PaddlePaddle >= 2.0.0-rc * Python >= 3.5+ @@ -45,13 +42,12 @@ PaddleGAN work with: pip install -U paddlepaddle-gpu ``` -### 2. install ppgan - +### 2. 安装ppgan ``` python -m pip install 'git+https://github.com/PaddlePaddle/PaddleGAN.git' ``` -Or install it from a local clone +或者通过将项目克隆到本地 ``` git clone https://github.com/PaddlePaddle/PaddleGAN cd PaddleGAN @@ -59,30 +55,30 @@ cd PaddleGAN pip install -v -e . # or "python setup.py develop" ``` -## Data Prepare -Please refer to [data prepare](./docs/data_prepare.md) for dataset preparation. +## 数据准备 +请参考 [数据准备](./docs/data_prepare.md) 来准备对应的数据. -## Get Start -Please refer [get started](./docs/get_started.md) for the basic usage of PaddleGAN. -## Model tutorial +## 快速开始 +训练,预测,推理等请参考 [快速开始](./docs/get_started.md). + +## 模型教程 * [Pixel2Pixel and CycleGAN](./docs/tutorials/pix2pix_cyclegan.md) * [PSGAN](./docs/tutorials/psgan.md) -* [Video restore](./docs/tutorails/video_restore.md) -* [Motion driving](./docs/tutorials/motion_driving.md) +* [视频修复](./docs/tutorials/video_restore.md) +* [动作驱动](./docs/tutorials/motion_driving.md) + +## 许可证书 +本项目的发布受[Apache 2.0 license](LICENSE)许可认证。 -## License -PaddleGAN is released under the [Apache 2.0 license](LICENSE). -## Contributing +## 贡献代码 -Contributions and suggestions are highly welcomed. Most contributions require you to agree to a [Contributor License Agreement (CLA)](https://cla-assistant.io/PaddlePaddle/PaddleGAN) declaring. -When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA. Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. -For more, please reference [contribution guidelines](docs/CONTRIBUTE.md). +我们非常欢迎你可以为PaddleGAN提供任何贡献和建议。大多数贡献都需要你同意参与者许可协议(CLA)。当你提交拉取请求时,CLA机器人会自动检查你是否需要提供CLA。 只需要按照机器人提供的说明进行操作即可。CLA只需要同意一次,就能应用到所有的代码仓库上。关于更多的流程请参考[贡献指南](docs/CONTRIBUTE.md)。 -## External Projects +## 外部项目 -External gan projects in the community that base on PaddlePaddle: +外部基于飞桨的生成对抗网络模型 + [PaddleGAN](https://github.com/PaddlePaddle/PaddleGAN) diff --git a/README_cn.md b/README_cn.md deleted file mode 100644 index ad40a4868953e..0000000000000 --- a/README_cn.md +++ /dev/null @@ -1,84 +0,0 @@ -[English](./README.md) | 简体中文 - -# PaddleGAN - -PaddleGAN 是一个基于飞桨的生成对抗网络开发工具包. - -### 图片变换 -![](./docs/imgs/A2B.png) -![](./docs/imgs/B2A.png) - -### 妆容迁移 -![](./docs/imgs/makeup_shifter.png) - -### 老视频修复 -![](./docs/imgs/color_sr_peking.gif) - -### 超分辨率 -![](./docs/imgs/sr_demo.png) - -### 动作驱动 -![](./docs/imgs/first_order.gif) - -特性: - -- 高度的灵活性: - - 模块化设计,解耦各个网络组件,开发者轻松搭建、试用各种检测模型及优化策略,快速得到高性能、定制化的算法。 - -- 丰富的应用: - - PaddleGAN 提供了非常多的应用,比如说图像生成,图像修复,图像上色,视频补帧,人脸妆容迁移等. - -## 安装 - -### 1. 安装 paddlepaddle - -PaddleGAN 所需的版本: -* PaddlePaddle >= 2.0.0-rc -* Python >= 3.5+ - -``` -pip install -U paddlepaddle-gpu -``` - -### 2. 安装ppgan -``` -python -m pip install 'git+https://github.com/PaddlePaddle/PaddleGAN.git' -``` - -或者通过将项目克隆到本地 -``` -git clone https://github.com/PaddlePaddle/PaddleGAN -cd PaddleGAN - -pip install -v -e . # or "python setup.py develop" -``` - -## 数据准备 -请参考 [数据准备](./docs/data_prepare.md) 来准备对应的数据. - - -## 快速开始 -训练,预测,推理等请参考 [快速开始](./docs/get_started.md). - -## 模型教程 -* [Pixel2Pixel and CycleGAN](./docs/tutorals/pix2pix_cyclegan.md) -* [PSGAN](./docs/tutorals/psgan.md) -* [视频修复](./docs/tutorails/video_restore.md) -* [动作驱动](./docs/tutorials/motion_driving.md) - -## 许可证书 -本项目的发布受[Apache 2.0 license](LICENSE)许可认证。 - - -## 贡献代码 - -我们非常欢迎你可以为PaddleGAN提供任何贡献和建议。大多数贡献都需要你同意参与者许可协议(CLA)。当你提交拉取请求时,CLA机器人会自动检查你是否需要提供CLA。 只需要按照机器人提供的说明进行操作即可。CLA只需要同意一次,就能应用到所有的代码仓库上。关于更多的流程请参考[贡献指南](docs/CONTRIBUTE.md)。 - - -## 外部项目 - -外部基于飞桨的生成对抗网络模型 - -+ [PaddleGAN](https://github.com/PaddlePaddle/PaddleGAN) diff --git a/README_en.md b/README_en.md new file mode 100644 index 0000000000000..87bbcb42cecf1 --- /dev/null +++ b/README_en.md @@ -0,0 +1,88 @@ +English | [简体中文](./README_cn.md) + +# PaddleGAN + +PaddleGAN is an development kit of Generative Adversarial Network based on PaddlePaddle. + +### Image Translation +![](./docs/imgs/A2B.png) +![](./docs/imgs/B2A.png) + +### Makeup shifter +![](./docs/imgs/makeup_shifter.png) + +### Old video restore +![](./docs/imgs/color_sr_peking.gif) + +### Super resolution + +![](./docs/imgs/sr_demo.png) + +### Motion driving +![](./docs/imgs/first_order.gif) + +Features: + +- Highly Flexible: + + Components are designed to be modular. Model architectures, as well as data +preprocess pipelines, can be easily customized with simple configuration +changes. + +- Rich applications: + + PaddleGAN provides rich of applications, such as image generation, image restore, image colorization, video interpolate, makeup shifter. + +## Install + +### 1. install paddlepaddle + +PaddleGAN work with: +* PaddlePaddle >= 2.0.0-rc +* Python >= 3.5+ + +``` +pip install -U paddlepaddle-gpu +``` + +### 2. install ppgan + +``` +python -m pip install 'git+https://github.com/PaddlePaddle/PaddleGAN.git' +``` + +Or install it from a local clone +``` +git clone https://github.com/PaddlePaddle/PaddleGAN +cd PaddleGAN + +pip install -v -e . # or "python setup.py develop" +``` + +## Data Prepare +Please refer to [data prepare](./docs/data_prepare.md) for dataset preparation. + +## Get Start +Please refer [get started](./docs/get_started.md) for the basic usage of PaddleGAN. + +## Model tutorial +* [Pixel2Pixel and CycleGAN](./docs/tutorials/pix2pix_cyclegan.md) +* [PSGAN](./docs/tutorials/psgan.md) +* [Video restore](./docs/tutorails/video_restore.md) +* [Motion driving](./docs/tutorials/motion_driving.md) + +## License +PaddleGAN is released under the [Apache 2.0 license](LICENSE). + +## Contributing + +Contributions and suggestions are highly welcomed. Most contributions require you to agree to a [Contributor License Agreement (CLA)](https://cla-assistant.io/PaddlePaddle/PaddleGAN) declaring. +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA. Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. +For more, please reference [contribution guidelines](docs/CONTRIBUTE.md). + + +## External Projects + +External gan projects in the community that base on PaddlePaddle: + ++ [PaddleGAN](https://github.com/PaddlePaddle/PaddleGAN) diff --git a/applications/tools/video-enhance.py b/applications/tools/video-enhance.py index 40f066df81499..23f6fc728e239 100644 --- a/applications/tools/video-enhance.py +++ b/applications/tools/video-enhance.py @@ -49,6 +49,10 @@ type=float, default=0.5, help='choose the time steps') +parser.add_argument('--remove_duplicates', + action='store_true', + default=False, + help='whether to remove duplicated frames') # DeepRemaster args parser.add_argument('--reference_dir', type=str, @@ -88,7 +92,8 @@ paddle.enable_static() predictor = DAINPredictor(args.output, weight_path=args.DAIN_weight, - time_step=args.time_step) + time_step=args.time_step, + remove_duplicates=args.remove_duplicates) frames_path, temp_video_path = predictor.run(temp_video_path) paddle.disable_static() elif order == 'DeepRemaster': diff --git a/configs/cyclegan_cityscapes.yaml b/configs/cyclegan_cityscapes.yaml index 74c32599719ee..66daebff3f778 100644 --- a/configs/cyclegan_cityscapes.yaml +++ b/configs/cyclegan_cityscapes.yaml @@ -6,21 +6,20 @@ lambda_identity: 0.5 model: name: CycleGANModel - defaults: &defaults - norm_type: instance - input_nc: 3 generator: name: ResnetGenerator output_nc: 3 n_blocks: 9 ngf: 64 use_dropout: False - <<: *defaults + norm_type: instance + input_nc: 3 discriminator: name: NLayerDiscriminator ndf: 64 n_layers: 3 - <<: *defaults + norm_type: instance + input_nc: 3 gan_mode: lsgan dataset: diff --git a/configs/cyclegan_horse2zebra.yaml b/configs/cyclegan_horse2zebra.yaml index 6d4c6d5648cb2..7c098ddf5417a 100644 --- a/configs/cyclegan_horse2zebra.yaml +++ b/configs/cyclegan_horse2zebra.yaml @@ -6,21 +6,20 @@ lambda_identity: 0.5 model: name: CycleGANModel - defaults: &defaults - norm_type: instance - input_nc: 3 generator: name: ResnetGenerator output_nc: 3 n_blocks: 9 ngf: 64 use_dropout: False - <<: *defaults + norm_type: instance + input_nc: 3 discriminator: name: NLayerDiscriminator ndf: 64 n_layers: 3 - <<: *defaults + norm_type: instance + input_nc: 3 gan_mode: lsgan dataset: @@ -39,7 +38,7 @@ dataset: size: [286, 286] interpolation: 'bicubic' #cv2.INTER_CUBIC - name: RandomCrop - output_size: [256, 256] + size: [256, 256] - name: RandomHorizontalFlip prob: 0.5 - name: Transpose @@ -55,8 +54,7 @@ dataset: output_nc: 3 serial_batches: False pool_size: 50 - transform: - transform: + transforms: - name: Resize size: [256, 256] interpolation: 'bicubic' #cv2.INTER_CUBIC diff --git a/docs/data_prepare.md b/docs/data_prepare.md index 6c25aa214c4e4..546f09f433f99 100644 --- a/docs/data_prepare.md +++ b/docs/data_prepare.md @@ -1,6 +1,6 @@ -## data prepare +## 数据准备 -It is recommended to symlink the dataset root to `$PaddleGAN/data`. +推荐把数据集软链接到 `$PaddleGAN/data`. 软链接后的目录结构如下图所示: ``` PaddleGAN @@ -28,8 +28,8 @@ PaddleGAN ``` -### cyclegan datasets -more dataset for cyclegan you can download from [here](https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/) +### cyclegan 相关的数据集下载 +cyclgan模型相关的数据集可以在[这里](https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/)下载 -### pix2pix datasets -more dataset for pix2pix you can download from [here](hhttps://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/) +### pix2pix 相关的数据集下载 +pixel2pixel模型相关的数据集可以在[这里](hhttps://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/)下载 diff --git a/docs/data_prepare_en.md b/docs/data_prepare_en.md new file mode 100644 index 0000000000000..6c25aa214c4e4 --- /dev/null +++ b/docs/data_prepare_en.md @@ -0,0 +1,35 @@ +## data prepare + +It is recommended to symlink the dataset root to `$PaddleGAN/data`. + +``` +PaddleGAN +|-- configs +|-- data +| |-- cityscapes +| | ├── test +| | ├── testA +| | ├── testB +| | ├── train +| | ├── trainA +| | └── trainB +| ├── horse2zebra +| | ├── testA +| | ├── testB +| | ├── trainA +| | └── trainB +| └── facades +| ├── test +| ├── train +| └── val +|-- docs +|-- ppgan +|-- tools + +``` + +### cyclegan datasets +more dataset for cyclegan you can download from [here](https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/) + +### pix2pix datasets +more dataset for pix2pix you can download from [here](hhttps://people.eecs.berkeley.edu/~tinghuiz/projects/pix2pix/datasets/) diff --git a/docs/get_started.md b/docs/get_started.md index 024e8dec2bfac..a584d9c033298 100644 --- a/docs/get_started.md +++ b/docs/get_started.md @@ -1,7 +1,7 @@ -## Getting started with PaddleGAN +## 快速开始使用PaddleGAN -### Train +### 训练 ``` python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml ``` @@ -16,7 +16,7 @@ multiple gpus train: CUDA_VISIBLE_DEVICES=0,1 python -m paddle.distributed.launch tools/main.py --config-file configs/pix2pix_cityscapes.yaml ``` -### Evaluate +### 预测 ``` python tools/main.py --config-file configs/cyclegan_cityscapes.yaml --evaluate-only --load your_weight_path ``` diff --git a/docs/get_started_en.md b/docs/get_started_en.md new file mode 100644 index 0000000000000..024e8dec2bfac --- /dev/null +++ b/docs/get_started_en.md @@ -0,0 +1,22 @@ + +## Getting started with PaddleGAN + +### Train +``` +python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml +``` + +continue train from last checkpoint +``` +python -u tools/main.py --config-file configs/cyclegan_cityscapes.yaml --resume your_checkpoint_path +``` + +multiple gpus train: +``` +CUDA_VISIBLE_DEVICES=0,1 python -m paddle.distributed.launch tools/main.py --config-file configs/pix2pix_cityscapes.yaml +``` + +### Evaluate +``` +python tools/main.py --config-file configs/cyclegan_cityscapes.yaml --evaluate-only --load your_weight_path +``` diff --git a/docs/tutorials/imgs/dain_network.png b/docs/tutorials/imgs/dain_network.png new file mode 100644 index 0000000000000..0af436858a8f6 Binary files /dev/null and b/docs/tutorials/imgs/dain_network.png differ diff --git a/docs/tutorials/imgs/deoldify_network.png b/docs/tutorials/imgs/deoldify_network.png new file mode 100644 index 0000000000000..dc73a188cdf13 Binary files /dev/null and b/docs/tutorials/imgs/deoldify_network.png differ diff --git a/docs/tutorials/imgs/edvr_network.png b/docs/tutorials/imgs/edvr_network.png new file mode 100644 index 0000000000000..5843aab9b1a46 Binary files /dev/null and b/docs/tutorials/imgs/edvr_network.png differ diff --git a/docs/tutorials/imgs/realsr_network.png b/docs/tutorials/imgs/realsr_network.png new file mode 100644 index 0000000000000..e41ff89f5cbe8 Binary files /dev/null and b/docs/tutorials/imgs/realsr_network.png differ diff --git a/docs/tutorials/imgs/remaster_network.png b/docs/tutorials/imgs/remaster_network.png new file mode 100644 index 0000000000000..9ddc26a5d411e Binary files /dev/null and b/docs/tutorials/imgs/remaster_network.png differ diff --git a/docs/tutorials/video_restore.md b/docs/tutorials/video_restore.md index 92ca73667e885..ec999e594fb2f 100644 --- a/docs/tutorials/video_restore.md +++ b/docs/tutorials/video_restore.md @@ -1 +1,115 @@ -## to be added +## 老视频修复 + +老视频往往具有帧数少,无色彩,分辨率低等特点。于是针对这些特点,我们使用补帧,上色,超分等模型对视频进行修复。 + +### 使用applications中的video-enhance.py工具进行快速开始视频修复 +``` +cd applications +python tools/video-enhance.py --input you_video_path.mp4 --proccess_order DAIN DeOldify EDVR --output output_dir +``` +#### 参数 + +- `--input (str)`: 输入的视频路径。 +- `--output (str)`: 输出的视频路径。 +- `--proccess_order`: 调用的模型名字和顺序,比如输入为 `DAIN DeOldify EDVR`,则会顺序调用 `DAINPredictor` `DeOldifyPredictor` `EDVRPredictor` 。 + +#### 效果展示 +![](../imgs/color_sr_peking.gif) + + +### 快速体验 +我们在ai studio制作了一个[ai studio 老北京视频修复教程](https://aistudio.baidu.com/aistudio/projectdetail/1161285) + +### 注意事项 + +* 在使用本教程前,请确保您已经[安装完paddle和ppgan]()。 + +* 本教程的所有命令都基于PaddleGAN/applications主目录进行执行。 + +* 各个模型耗时较长,尤其使超分辨率模型,建议输入的视频分辨率低一些,时长短一些。 + +* 需要运行在gpu环境上 + +### ppgan提供的可用于视频修复的预测api简介 +可以根据要修复的视频的特点,使用不同的模型与参数 + +### 补帧模型DAIN +DAIN 模型通过探索深度的信息来显式检测遮挡。并且开发了一个深度感知的流投影层来合成中间流。在视频补帧方面有较好的效果。 +![](./imgs/dain_network.png) + +``` +ppgan.apps.DAINPredictor( + output_path='output', + weight_path=None, + time_step=None, + use_gpu=True, + remove_duplicates=False) +``` +#### 参数 + +- `output_path (str,可选的)`: 输出的文件夹路径,默认值:`output`. +- `weight_path (None,可选的)`: 载入的权重路径,如果没有设置,则从云端下载默认的权重到本地。默认值:`None`。 +- `time_step (int)`: 补帧的时间系数,如果设置为0.5,则原先为每秒30帧的视频,补帧后变为每秒60帧。 +- `remove_duplicates (bool,可选的)`: 是否删除重复帧,默认值:`False`. + +### 上色模型DeOldifyPredictor +DeOldify 采用自注意力机制的生成对抗网络,生成器是一个U-NET结构的网络。在图像的上色方面有着较好的效果。 +![](./imgs/deoldify_network.png) + +``` +ppgan.apps.DeOldifyPredictor(output='output', weight_path=None, render_factor=32) +``` +#### 参数 + +- `output_path (str,可选的)`: 输出的文件夹路径,默认值:`output`. +- `weight_path (None,可选的)`: 载入的权重路径,如果没有设置,则从云端下载默认的权重到本地。默认值:`None`。 +- `render_factor (int)`: 会将该参数乘以16后作为输入帧的resize的值,如果该值设置为32, + 则输入帧会resize到(32 * 16, 32 * 16)的尺寸再输入到网络中。 + +### 上色模型DeepRemasterPredictor +DeepRemaster 模型基于时空卷积神经网络和自注意力机制。并且能够根据输入的任意数量的参考帧对图片进行上色。 +![](./imgs/remaster_network.png) + +``` +ppgan.apps.DeepRemasterPredictor( + output='output', + weight_path=None, + colorization=False, + reference_dir=None, + mindim=360): +``` +#### 参数 + +- `output_path (str,可选的)`: 输出的文件夹路径,默认值:`output`. +- `weight_path (None,可选的)`: 载入的权重路径,如果没有设置,则从云端下载默认的权重到本地。默认值:`None`。 +- `colorization (bool)`: 是否对输入视频上色,如果选项设置为 `True` ,则参考帧的文件夹路径也必须要设置。默认值:`False`。 +- `reference_dir (bool)`: 参考帧的文件夹路径。默认值:`None`。 +- `mindim (bool)`: 输入帧重新resize后的短边的大小。默认值:360。 + +### 超分辨率模型RealSRPredictor +RealSR模型通过估计各种模糊内核以及实际噪声分布,为现实世界的图像设计一种新颖的真实图片降采样框架。基于该降采样框架,可以获取与真实世界图像共享同一域的低分辨率图像。并且提出了一个旨在提高感知度的真实世界超分辨率模型。对合成噪声数据和真实世界图像进行的大量实验表明,该模型能够有效降低了噪声并提高了视觉质量。 + +![](./imgs/realsr_network.png) + +``` +ppgan.apps.RealSRPredictor(output='output', weight_path=None) +``` +#### 参数 + +- `output_path (str,可选的)`: 输出的文件夹路径,默认值:`output`. +- `weight_path (None,可选的)`: 载入的权重路径,如果没有设置,则从云端下载默认的权重到本地。默认值:`None`。 +- +### 超分辨率模型EDVRPredictor +EDVR模型提出了一个新颖的视频具有增强可变形卷积的还原框架:第一,为了处理大动作而设计的一个金字塔,级联和可变形(PCD)对齐模块,使用可变形卷积以从粗到精的方式在特征级别完成对齐;第二,提出时空注意力机制(TSA)融合模块,在时间和空间上都融合了注意机制,用以增强复原的功能。 + +EDVR模型是一个基于连续帧的超分模型,能够有效利用帧间的信息,速度比RealSR模型快。 + +![](./imgs/edvr_network.png) + +``` +ppgan.apps.EDVRPredictor(output='output', weight_path=None) +``` +#### 参数 + +- `output_path (str,可选的)`: 输出的文件夹路径,默认值:`output`. +- `weight_path (None,可选的)`: 载入的权重路径,如果没有设置,则从云端下载默认的权重到本地。默认值:`None`。 diff --git a/ppgan/datasets/single_dataset.py b/ppgan/datasets/single_dataset.py index 87981b42bedf1..b2b745461fe8c 100644 --- a/ppgan/datasets/single_dataset.py +++ b/ppgan/datasets/single_dataset.py @@ -4,13 +4,13 @@ from .image_folder import make_dataset from .builder import DATASETS +from .transforms.builder import build_transforms @DATASETS.register() class SingleDataset(BaseDataset): """ """ - def __init__(self, cfg): """Initialize this dataset class. @@ -20,7 +20,7 @@ def __init__(self, cfg): BaseDataset.__init__(self, cfg) self.A_paths = sorted(make_dataset(cfg.dataroot, cfg.max_dataset_size)) input_nc = self.cfg.output_nc if self.cfg.direction == 'BtoA' else self.cfg.input_nc - self.transform = get_transform(cfg.transform, grayscale=(input_nc == 1)) + self.transform = build_transforms(self.cfg.transforms) def __getitem__(self, index): """Return a data point and its metadata information.