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

[Feature] Support Evaluation Hook of Translation Models #127

Merged
merged 6 commits into from
Oct 15, 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
solve conflict
  • Loading branch information
yangyifei authored and yangyifei committed Oct 14, 2021
commit bf862799aca49a5296753300e0eebaa31c443448
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
7 changes: 5 additions & 2 deletions configs/cyclegan/cyclegan_lsgan_resnet_in_1x1_80k_facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
7 changes: 5 additions & 2 deletions configs/pix2pix/pix2pix_vanilla_unet_bn_1x1_80k_facades.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
interval=10000,
metrics=[
dict(type='FID', num_images=num_images, bgr2rgb=True),
dict(type='IS', num_images=num_images, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=num_images,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])
best_metric=['fid', 'is'])
21 changes: 11 additions & 10 deletions mmgen/core/evaluation/eval_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ def _save_best_ckpt(self, runner, new_score, metric_name):
class TranslationEvalHook(GenerativeEvalHook):
"""Evaluation Hook for Translation Models.

This evaluation hook can be used to evaluate translation models. Note
that only ``FID`` and ``IS`` metric are supported for the distributed
training now. In the future, we will support more metrics for the
This evaluation hook can be used to evaluate translation models. Note
that only ``FID`` and ``IS`` metric are supported for the distributed
training now. In the future, we will support more metrics for the
evaluation during the training procedure.

In our config system, you only need to add `evaluation` with the detailed
Expand Down Expand Up @@ -364,7 +364,10 @@ class TranslationEvalHook(GenerativeEvalHook):
interval=10000,
metrics=[
dict(type='FID', num_images=106, bgr2rgb=True),
dict(type='IS', num_images=106, inception_args=dict(type='pytorch'))
dict(
type='IS',
num_images=106,
inception_args=dict(type='pytorch'))
],
best_metric=['fid', 'is'])

Expand Down Expand Up @@ -392,7 +395,7 @@ class TranslationEvalHook(GenerativeEvalHook):
Args:
target_domain (str): Target domain of output image.
"""

def __init__(self, *args, target_domain, **kwargs):
super().__init__(*args, **kwargs)
self.target_domain = target_domain
Expand Down Expand Up @@ -431,7 +434,6 @@ def after_train_iter(self, runner):

mmcv.print_log(f'Sample {max_num_images} fake images for evaluation',
'mmgen')
batch_size = self.dataloader.batch_size

rank, ws = get_dist_info()

Expand All @@ -452,8 +454,7 @@ def after_train_iter(self, runner):
fakes = output_dict['target']
# key Error
else:
raise KeyError(
'Cannot found key for images in data_dict. ')
raise KeyError('Cannot found key for images in data_dict. ')
# sampling fake images and directly send them to metrics
# pbar update number for one proc
num_update = 0
Expand All @@ -467,7 +468,7 @@ def after_train_iter(self, runner):

if rank == 0:
if num_update > 0:
pbar.update(num_update* ws)
pbar.update(num_update * ws)

runner.log_buffer.clear()
# a dirty walkround to change the line at the end of pbar
Expand All @@ -488,4 +489,4 @@ def after_train_iter(self, runner):

# clear all current states for next evaluation
for metric in self.metrics:
metric.clear()
metric.clear()
2 changes: 1 addition & 1 deletion mmgen/datasets/paired_image_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PairedImageDataset(Dataset):
pipeline (List[dict | callable]): A sequence of data transformations.
test_mode (bool): Store `True` when building test dataset.
Default: `False`.
testdir (str): Subfolder of dataroot which contain test images.
testdir (str): Subfolder of dataroot which contain test images.
Default: 'test'.
"""

Expand Down