You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-94Lines changed: 31 additions & 94 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
## StyleGAN2-ADA for generation of synthetic skin lesions
2
+

2
3
3
4
The usage of healthcare data in the development of artificial intelligence (AI) models is associated with issues around personal integrity and regulations. Patient data can usually not be freely shared and thus, the utility of it in creating AI solutions is limited. The main goal of the project was to explore GANs to generate synthetic data of skin lesions and test the performance of DL models train on that type of data in comparison to trained only on real one.
Note: The Docker image requires NVIDIA driver release `r455.23` or later.
49
-
50
-
**Legacy networks**: The above commands can load most of the network pickles created using the previous TensorFlow versions of StyleGAN2 and StyleGAN2-ADA. However, for future compatibility, we recommend converting such legacy pickles into the new format used by the PyTorch version:
For optimal results, the target image should be cropped and aligned similar to the [FFHQ dataset](https://github.com/NVlabs/ffhq-dataset). The above command saves the projection target `out/target.png`, result `out/proj.png`, latent vector `out/projected_w.npz`, and progression video `out/proj.mp4`. You can render the resulting latent vector by specifying `--projected_w` for `generate.py` for specific melanoma class:
You can use pre-trained networks in your own Python code as follows:
77
-
78
-
```.python
79
-
with open('ffhq.pkl', 'rb') as f:
80
-
G = pickle.load(f)['G_ema'].cuda() # torch.nn.Module
81
-
z = torch.randn([1, G.z_dim]).cuda() # latent codes
82
-
c = None # class labels (not used in this example)
83
-
img = G(z, c) # NCHW, float32, dynamic range [-1, +1]
84
-
```
85
-
86
-
The above code requires `torch_utils` and `dnnlib` to be accessible via `PYTHONPATH`. It does not need source code for the networks themselves — their class definitions are loaded from the pickle via `torch_utils.persistence`.
87
-
88
-
The pickle contains three networks. `'G'` and `'D'` are instantaneous snapshots taken during training, and `'G_ema'` represents a moving average of the generator weights over several training steps. The networks are regular instances of `torch.nn.Module`, with all of their parameters and buffers placed on the CPU at import and gradient computation disabled by default.
89
-
90
-
The generator consists of two submodules, `G.mapping` and `G.synthesis`, that can be executed separately. They also support various additional options:
91
-
92
-
```.python
93
-
w = G.mapping(z, c, truncation_psi=0.5, truncation_cutoff=8)
In its most basic form, training new networks boils down to:
118
66
@@ -139,7 +87,7 @@ The training configuration can be further customized with additional command lin
139
87
140
88
Please refer to [`python train.py --help`](./docs/train-help.txt) for the full list.
141
89
142
-
## Expected training time
90
+
## Expected training time - NVIDIA resources
143
91
144
92
The total training time depends heavily on resolution, number of GPUs, dataset, desired quality, and hyperparameters. The following table lists expected wallclock times to reach different points in the training, measured in thousands of real images shown to the discriminator ("kimg"):
145
93
@@ -168,7 +116,7 @@ In typical cases, 25000 kimg or more is needed to reach convergence, but the res
Note: `--cfg=auto` serves as a reasonable first guess for the hyperparameters but it does not necessarily lead to optimal results for a given dataset. For example, `--cfg=stylegan2` yields considerably better FID for FFHQ-140k at 1024x1024 than illustrated above. We recommend trying out at least a few different values of `--gamma` for each new dataset.
119
+
Note: `--cfg=auto` serves as a reasonable first guess for the hyperparameters but it does not necessarily lead to optimal results for a given dataset. We recommend trying out at least a few different values of `--gamma` for each new dataset.
172
120
173
121
## Quality metrics
174
122
@@ -178,46 +126,35 @@ Additional quality metrics can also be computed after the training:
178
126
179
127
```.bash
180
128
# Previous training run: look up options automatically, save result to JSONL file.
The above command saves the projection target `out/target.png`, result `out/proj.png`, latent vector `out/projected_w.npz`, and progression video `out/proj.mp4`. You can render the resulting latent vector by specifying `--projected_w` for `generate.py` for specific melanoma class:
The first example looks up the training configuration and performs the same operation as if `--metrics=pr50k3_full` had been specified during training. The second example downloads a pre-trained network pickle, in which case the values of `--mirror` and `--data` must be specified explicitly.
190
-
191
-
Note that many of the metrics have a significant one-off cost when calculating them for the first time for a new dataset (up to 30min). Also note that the evaluation is done using a different random seed each time, so the results will vary if the same metric is computed multiple times.
192
-
193
-
We employ the following metrics in the ADA paper. Execution time and GPU memory usage is reported for one NVIDIA Tesla V100 GPU at 1024x1024 resolution:
194
-
195
-
| Metric | Time | GPU mem | Description |
196
-
| :----- | :----: | :-----: | :---------- |
197
-
| `fid50k_full` | 13 min | 1.8 GB | Fréchet inception distance<sup>[1]</sup> against the full dataset
198
-
| `kid50k_full` | 13 min | 1.8 GB | Kernel inception distance<sup>[2]</sup> against the full dataset
199
-
| `pr50k3_full` | 13 min | 4.1 GB | Precision and recall<sup>[3]</sup> againt the full dataset
200
-
| `is50k` | 13 min | 1.8 GB | Inception score<sup>[4]</sup> for CIFAR-10
201
-
202
-
In addition, the following metrics from the [StyleGAN](https://github.com/NVlabs/stylegan) and [StyleGAN2](https://github.com/NVlabs/stylegan2) papers are also supported:
0 commit comments