Skip to content

Commit

Permalink
[Bug] Save gt images in PGGAN's forward (#1328)
Browse files Browse the repository at this point in the history
* save gt image to data samples in forward

* add ut to ensure gt img is saved
  • Loading branch information
LeoXing1996 authored Oct 18, 2022
1 parent 1dd0529 commit 6498c61
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mmedit/models/editors/pggan/pggan.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def forward(self,
gen_sample = EditDataSample()
if data_samples:
gen_sample.update(data_samples[idx])
if isinstance(inputs, dict) and 'img' in inputs:
gen_sample.gt_img = PixelData(data=inputs['img'][idx])
if isinstance(outputs, dict):
gen_sample.ema = EditDataSample(
fake_img=PixelData(data=outputs['ema'][idx]),
Expand Down
4 changes: 4 additions & 0 deletions tests/test_models/test_editors/test_pggan/test_pggan.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def test_pggan_cpu(self):
assert np.isclose(pggan._actual_nkimgs[-1], 0.012, atol=1e-8)

# test forward
outputs = pggan.forward(dict(img=torch.randn(3, 3, 16, 16)))
assert len(outputs) == 3
assert all(['gt_img' in out for out in outputs])

outputs = pggan.forward(dict(num_batches=2))
assert len(outputs) == 2
assert all([out.fake_img.data.shape == (3, 16, 16) for out in outputs])
Expand Down

0 comments on commit 6498c61

Please sign in to comment.