Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Revise typos in eval_hook.py #138

Merged
merged 4 commits into from
Oct 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix typo
  • Loading branch information
LeoXing1996 committed Oct 15, 2021
commit c53cc39dc209af1ce07926857da6471193151ee0
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ repos:
rev: v2.1.0
hooks:
- id: codespell
args: ["--skip", "*.ipynb,tools/data/hvu/label_map.json", "-L", "formating,te,nd,thre,Gool,gool"]
args: ["--skip", "*.ipynb,tools/data/hvu/label_map.json", "-L", "formating,te,nd,thre,Gool,gool,lod"]
2 changes: 1 addition & 1 deletion apps/conditional_interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def parse_args():
parser.add_argument(
'--fix-z',
action='store_true',
help='whether to fix the noise for conditonal model')
help='whether to fix the noise for conditional model')
parser.add_argument(
'--fix-y',
action='store_true',
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/imagenet_noaug_128.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# different from mmcls, we adopt the setting used in BigGAN.
# Importantly, the `to_rgb` is set to `False` to remain image orders as BGR.
# Remove `RandomFlip` augmentation and change `RandomCropLongEdge` to
# `CenterCropLongEdge` to elminate randomness.
# `CenterCropLongEdge` to elminiate randomness.
img_norm_cfg = dict(
mean=[127.5, 127.5, 127.5], std=[127.5, 127.5, 127.5], to_rgb=False)
train_pipeline = [
Expand Down
2 changes: 1 addition & 1 deletion configs/_base_/datasets/imagenet_noaug_256.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# different from mmcls, we adopt the setting used in BigGAN.
# Importantly, the `to_rgb` is set to `False` to remain image orders as BGR.
# Remove `RandomFlip` augmentation and change `RandomCropLongEdge` to
# `CenterCropLongEdge` to elminate randomness.
# `CenterCropLongEdge` to elminiate randomness.
img_norm_cfg = dict(
mean=[127.5, 127.5, 127.5], std=[127.5, 127.5, 127.5], to_rgb=False)
train_pipeline = [
Expand Down
2 changes: 1 addition & 1 deletion configs/biggan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Evaluation of our trained BIgGAN.
Note: This is an unfinished version (1150k iter) of BigGAN trained on `ImageNet1k`. The model with the best performance is still on the way.

## Converted weights
Since we havn't finished training our models, we provide you with several pre-trained weights which have been evaluated. Here, we refer to [BigGAN-PyTorch](https://github.com/ajbrock/BigGAN-PyTorch) and [pytorch-pretrained-BigGAN](https://github.com/huggingface/pytorch-pretrained-BigGAN).
Since we haven't finished training our models, we provide you with several pre-trained weights which have been evaluated. Here, we refer to [BigGAN-PyTorch](https://github.com/ajbrock/BigGAN-PyTorch) and [pytorch-pretrained-BigGAN](https://github.com/huggingface/pytorch-pretrained-BigGAN).

Evaluation results and download links are provided below.

Expand Down
4 changes: 2 additions & 2 deletions configs/sngan_proj/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
| sngan_proj_32 | CIFAR10 | w | 5 | 500000 | [9.5564 (490000)](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_cifar10_32_lr-2e-4_b64x1_wReLUinplace_is-iter490000_20210709_202230-cd863c74.pth) | [8.3462 (490000)](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_cifar10_32_lr-2e-4-b64x1_wReLUinplace_fid-iter490000_20210709_203038-191b2648.pth) | [config](https://github.com/open-mmlab/mmgeneration/tree/master/configs/sngan_proj/sngan_proj_32_wReLUinplace_lr-2e-4_ndisc5_cifar10_b64x1.py) | [Log](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_cifar10_32_lr-2e-4_b64x1_wReLUinplace_20210624_063454_is-cd863c74_fid-191b2648.json) |
| sngan_proj_128 | ImageNet | w/o | 5 | 1000000 | [30.0651 (952000)](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_imagenet1k_128_Glr2e-4_Dlr5e-5_ndisc5_b128x2_woReLUinplace_is-iter952000_20210730_132027-9c884a21.pth) | [32.6193 (988000)](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_imagenet1k_128_Glr2e-4_Dlr5e-5_ndisc5_b128x2_woReLUinplace_fid-iter988000_20210730_131424-061bf803.pth) | [config](https://github.com/open-mmlab/mmgeneration/tree/master/configs/sngan_proj/sngan_proj_128_woReLUinplace_Glr-2e-4_Dlr-5e-5_ndisc5_imagenet1k_b128x2.py) | [Log](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_imagenet1k_128_Glr2e-4_Dlr5e-5_ndisc5_b128x2_woReLUinplace_20210730_131424_fid-061bf803_is-9c884a21.json) |
| sngan_proj_128 | ImageNet | w | 5 | 1000000 | [28.1799 (944000)](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_imagenet1k_128_Glr2e-4_Dlr5e-5_ndisc5_b128x2_wReLUinplace_is-iter944000_20210730_132714-ca0ccd07.pth) | [33.4821 (988000)](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_imagenet1k_128_Glr2e-4_Dlr5e-5_ndisc5_b128x2_wReLUinplace_fid-iter988000_20210730_132401-9a682411.pth) | [config](https://github.com/open-mmlab/mmgeneration/tree/master/configs/sngan_proj/sngan_proj_128_wReLUinplace_Glr-2e-4_Dlr-5e-5_ndisc5_imagenet1k_b128x2.py) | [Log](https://download.openmmlab.com/mmgen/sngan_proj/sngan_proj_imagenet1k_128_Glr2e-4_Dlr5e-5_ndisc5_b128x2_wReLUinplace_20210730_132401_fid-9a682411_is-ca0ccd07.json) |
| sngan_proj_128 | ImageNet | w/o | 2 | 2000000 | Coming soon | Comming soon | Comming Soon | Comming Soon |
| sngan_proj_128 | ImageNet | w | 2 | 2000000 | Coming soon | Comming soon | Comming Soon | Comming Soon |
| sngan_proj_128 | ImageNet | w/o | 2 | 2000000 | Coming soon | Coming soon | Coming Soon | Coming Soon |
| sngan_proj_128 | ImageNet | w | 2 | 2000000 | Coming soon | Coming soon | Coming Soon | Coming Soon |

'\*' Iteration counting rule in our implementation is different from others. If you want to align with other codebases, you can use the following conversion formula:
```
Expand Down
2 changes: 1 addition & 1 deletion configs/styleganv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bash tools/dist_train.sh \
--work-dir ./work_dirs/quick-test
```

With a simliar way, users can switch to [config for partial-GD](https://github.com/open-mmlab/mmgeneration/tree/master/configs/styleganv2/stylegan2_c2_fp16_quicktest_ffhq_256_b4x8_800k.py) and [config for globalG-partialD](https://github.com/open-mmlab/mmgeneration/tree/master/configs/styleganv2/stylegan2_c2_fp16-globalG-partialD_PL-R1-no-scaler_ffhq_256_b4x8_800k.py) to test the other two mixed precision training configuration.
With a similar way, users can switch to [config for partial-GD](https://github.com/open-mmlab/mmgeneration/tree/master/configs/styleganv2/stylegan2_c2_fp16_quicktest_ffhq_256_b4x8_800k.py) and [config for globalG-partialD](https://github.com/open-mmlab/mmgeneration/tree/master/configs/styleganv2/stylegan2_c2_fp16-globalG-partialD_PL-R1-no-scaler_ffhq_256_b4x8_800k.py) to test the other two mixed precision training configuration.


*Note that to use the [APEX](https://github.com/NVIDIA/apex) toolkit, you have to installed it following the official guidance. (APEX is not included in our requirements.) If you are using GPUs without tensor core, you would better to switch to the newer PyTorch version (>= 1.7,0). Otherwise, the APEX installation or running may meet several bugs.*
Expand Down
8 changes: 4 additions & 4 deletions docs/quick_run.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ from mmgen.apis import init_model, sample_img2img_model
config_file = 'configs/pix2pix/pix2pix_vanilla_unet_bn_wo_jitter_flip_1x4_186840_edges2shoes.py'
# you can download this checkpoint in advance and use a local file path.
checkpoint_file = 'https://download.openmmlab.com/mmgen/pix2pix/pix2pix_vanilla_unet_bn_wo_jitter_flip_1x4_186840_edges2shoes_convert-bgr_20210410_174116-aaaa3687.pth'
# Specify the path to image you want to transalte
# Specify the path to image you want to translate
image_path = 'tests/data/paired/test/33_AB.jpg'
device = 'cuda:0'
# init a generatvie
Expand Down Expand Up @@ -174,7 +174,7 @@ Then, users can use the evaluation script with the following command:
```shell
bash eval.sh ${CONFIG_FILE} ${CKPT_FILE} --batch-size 10 --online
```
If you are in slurm enviroment, please switch to the [tools/slurm_eval.sh](https://github.com/open-mmlab/mmgeneration/tree/master/tools/slurm_eval.sh) by using the following commands:
If you are in slurm environment, please switch to the [tools/slurm_eval.sh](https://github.com/open-mmlab/mmgeneration/tree/master/tools/slurm_eval.sh) by using the following commands:

```shell
bash slurm_eval.sh ${PLATFORM} ${JOBNAME} ${CONFIG_FILE} ${CONFIG_FILE} \
Expand Down Expand Up @@ -269,7 +269,7 @@ To be noted that, the selection of Inception V3 and image resize method can sign

We also perform a survey on the influence of data loading pipeline and the version of pretrained Inception V3 on the IS result. All IS are evaluated on the same group of images which are randomly selected from the ImageNet dataset.

<details> <summary> Show the Comparsion Results </summary>
<details> <summary> Show the Comparison Results </summary>

| Code Base | Inception V3 Version | Data Loader Backend | Resize Interpolation Method | IS |
| -- | -- | -- | -- | -- |
Expand Down Expand Up @@ -357,7 +357,7 @@ In this section, we will discuss how to evaluate the generative models, especial
In [eval_hooks.py](https://github.com/open-mmlab/mmgeneration/blob/master/mmgen/core/evaluation/eval_hooks.py), `GenerativeEvalHook` is provided to evaluate generative models duiring training. The most important argument for this hook is `metrics`. In fact, users can directly copy the configs in the last section to define the evaluation metric. To evaluate the model with `FID` metric, please add the following python codes in your config file:

```python
# define the evaluation keywords, otherwise evalution will not be
# define the evaluation keywords, otherwise evaluation will not be
# added in training
evaluation = dict(
type='GenerativeEvalHook',
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ custom_hooks = [ # add customized hooks for training

metrics = dict( # metrics we used to test this model
fid50k=dict(
inception_pkl='work_dirs/inception_pkl/ffhq-256-50k-rgb.pkl', # provdie the inception pkl for FID
inception_pkl='work_dirs/inception_pkl/ffhq-256-50k-rgb.pkl', # provide the inception pkl for FID
bgr2rgb=True)) # change the order of the image channel when extracting inception features

checkpoint_config = dict(interval=10000, by_epoch=False, max_keep_ckpts=30) # define checkpoint hook
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorials/inception_stat.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If `${FLIP}` is set as `True`, the following config of horizontal flip operation
dict(type='Flip', keys=['real_img'], direction='horizontal')
```

If you want to use a specific pipeline otherwise the pre-defiend ones, you can use `--pipeline-cfg` to pass a config file contains the data pipeline you want to use.
If you want to use a specific pipeline otherwise the pre-defined ones, you can use `--pipeline-cfg` to pass a config file contains the data pipeline you want to use.
```shell
python tools/utils/inception_stat.py --imgsdir ${IMGS_PATH} --pklname ${PKLNAME} --pipeline-cfg ${PIPELINE}
```
Expand Down
4 changes: 2 additions & 2 deletions mmgen/apis/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def sample_uncoditional_model(model,
"""
# set eval mode
model.eval()
# constrcut sampling list for batches
# construct sampling list for batches
n_repeat = num_samples // num_batches
batches_list = [num_batches] * n_repeat

Expand Down Expand Up @@ -111,7 +111,7 @@ def sample_conditional_model(model,
"""
# set eval mode
model.eval()
# constrcut sampling list for batches
# construct sampling list for batches
n_repeat = num_samples // num_batches
batches_list = [num_batches] * n_repeat

Expand Down
2 changes: 1 addition & 1 deletion mmgen/apis/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def set_random_seed(seed, deterministic=False, use_rank_shift=True):
"""Set random seed.

In this function, we just modify the default behavior of the simliar
In this function, we just modify the default behavior of the similar
function defined in MMCV.

Args:
Expand Down
6 changes: 3 additions & 3 deletions mmgen/core/evaluation/eval_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GenerativeEvalHook(Hook):
the evaluation during the training procedure.

In our config system, you only need to add `evaluation` with the detailed
configureations. Below is serveral usage cases for different situations.
configureations. Below is several usage cases for different situations.
What you need to do is to add these lines at the end of your config file.
Then, you can use this evaluation hook in the training procedure.

Expand All @@ -48,7 +48,7 @@ class GenerativeEvalHook(Hook):
bgr2rgb=True),
sample_kwargs=dict(sample_model='ema'))

#. Use FID and IS simutaneously and save the best checkpoints respectively
#. Use FID and IS simultaneously and save the best checkpoints respectively

.. code-block:: python
:linenos:
Expand Down Expand Up @@ -153,7 +153,7 @@ def __init__(self,
former, latter = self.milestones[idx], self.milestones[idx + 1]
if former >= latter:
raise ValueError(
'Elements in `milestones` shoule in ascending order.')
'Elements in `milestones` should in ascending order.')
else:
raise TypeError('`interval` only support `int` or `dict`,'
f'recieve {type(self.interval)} instead.')
Expand Down
2 changes: 1 addition & 1 deletion mmgen/core/evaluation/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def single_gpu_online_evaluation(model, data_loader, metrics, logger,
# generated in a metric-special way and not shared between different
# metrics.
# For reconstruction metrics like 'GaussianKLD', they do not
# receive images but receive a dict with cooresponding probabilistic
# receive images but receive a dict with corresponding probabilistic
# parameter.

special_metrics = []
Expand Down
2 changes: 1 addition & 1 deletion mmgen/core/evaluation/metric_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _hox_downsample(img):


def _f_special_gauss(size, sigma):
r"""Return a circularly symmetric gaussian kernel.
r"""Return a circular symmetric gaussian kernel.

Ref: https://github.com/tkarras/progressive_growing_of_gans/blob/master/metrics/ms_ssim.py # noqa

Expand Down
11 changes: 6 additions & 5 deletions mmgen/core/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ def __init__(self, num_images, image_shape=None):
self.image_shape = image_shape
self.num_real_need = num_images
self.num_fake_need = num_images
self.num_real_feeded = 0 # record of the feeded real images
self.num_fake_feeded = 0 # record of the feeded fake images
self.num_real_feeded = 0 # record of the fed real images
self.num_fake_feeded = 0 # record of the fed fake images
self._result_str = None # string of metric result

@property
Expand All @@ -385,7 +385,7 @@ def feed(self, batch, mode):
operation in 'feed_op' function.

Args:
batch (Tensor | dict): Images or dict to be feeded into
batch (Tensor | dict): Images or dict to be fed into
metric object. If ``Tensor`` is passed, the order of ``Tensor``
should be "NCHW". If ``dict`` is passed, each term in the
``dict`` are ``Tensor`` with order "NCHW".
Expand Down Expand Up @@ -736,6 +736,7 @@ def feed_op(self, minibatch, mode):
if mode == 'reals':
real_pyramid = laplacian_pyramid(minibatch, self.n_pyramids - 1,
self.gaussian_k)
# lod: layer_of_descriptors
for lod, level in enumerate(real_pyramid):
desc = get_descriptors_for_minibatch(level, self.nhood_size,
self.nhoods_per_image)
Expand Down Expand Up @@ -960,7 +961,7 @@ def extract_features(self, images):
class IS(Metric):
"""IS (Inception Score) metric.

The images are splitted into groups, and the inception score is calculated
The images are split into groups, and the inception score is calculated
on each group of images, then the mean and standard deviation of the score
is reported. The calculation of the inception score on a group of images
involves first using the inception v3 model to calculate the conditional
Expand Down Expand Up @@ -1034,7 +1035,7 @@ def __init__(self,

def pil_resize(self, x):
"""Apply Bicubic interpolation with Pillow backend. Before and after
interpolation operation, we have to perform a type convertion beteen
interpolation operation, we have to perform a type conversion between
torch.tensor and PIL.Image, and these operations make resize process a
bit slow.

Expand Down
2 changes: 1 addition & 1 deletion mmgen/core/hooks/ceph_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class PetrelUploadHook(Hook):
"""Upload Data with Petrel.

With this hook, users can easily upload datas to the cloud server for
With this hook, users can easily upload data to the cloud server for
saving local spaces. Please read the notes below for using this hook,
especially for the declaration of ``petrel``.

Expand Down
2 changes: 1 addition & 1 deletion mmgen/datasets/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def build_dataset(cfg, default_args=None):
Defaults to None.

Returns:
Objet: Dataset for sampling data batch.
Object: Dataset for sampling data batch.
"""
from .dataset_wrappers import RepeatDataset
if isinstance(cfg, (list, tuple)):
Expand Down
8 changes: 4 additions & 4 deletions mmgen/models/architectures/fid_inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def forward(self, x):
x (torch.Tensor): Input tensor of shape BxCxHxW.

Returns:
torch.Tensor: Feature Maps of x outputed by this block.
torch.Tensor: Feature Maps of x outputted by this block.
"""
branch1x1 = self.branch1x1(x)

Expand Down Expand Up @@ -230,7 +230,7 @@ def forward(self, x):
x (torch.Tensor): Input tensor of shape BxCxHxW.

Returns:
torch.Tensor: Feature Maps of x outputed by this block.
torch.Tensor: Feature Maps of x outputted by this block.
"""
branch1x1 = self.branch1x1(x)

Expand Down Expand Up @@ -267,7 +267,7 @@ def forward(self, x):
x (torch.Tensor): Input tensor of shape BxCxHxW.

Returns:
torch.Tensor: Feature Maps of x outputed by this block.
torch.Tensor: Feature Maps of x outputted by this block.
"""
branch1x1 = self.branch1x1(x)

Expand Down Expand Up @@ -309,7 +309,7 @@ def forward(self, x):
x (torch.Tensor): Input tensor of shape BxCxHxW.

Returns:
torch.Tensor: Feature Maps of x outputed by this block.
torch.Tensor: Feature Maps of x outputted by this block.
"""
branch1x1 = self.branch1x1(x)

Expand Down
Loading