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] Fix bug of real samples number calculation in DDP evaluation #150

Merged
merged 5 commits into from
Nov 23, 2021
Merged
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 bug
  • Loading branch information
LeoXing1996 committed Nov 2, 2021
commit c05d68246d25e515af919e9ed536fa3afc340f4e
17 changes: 12 additions & 5 deletions mmgen/core/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,31 +398,38 @@ def feed(self, batch, mode):
return 0

if isinstance(batch, dict):
batch_size = [v for v in batch.values()][0].shape[0] * ws
batch_size = [v for v in batch.values()][0].shape[0]
end = min(batch_size,
self.num_real_need - self.num_real_feeded)
batch_to_feed = {k: v[:end, ...] for k, v in batch.items()}
else:
batch_size = batch.shape[0] * ws
batch_size = batch.shape[0]
end = min(batch_size,
self.num_real_need - self.num_real_feeded)
batch_to_feed = batch[:end, ...]

#
total_end = min(batch * ws,
self.num_real_need - self.num_real_feeded)
self.feed_op(batch_to_feed, mode)
self.num_real_feeded += end
self.num_real_feeded += total_end
return end

elif mode == 'fakes':
if self.num_fake_feeded == self.num_fake_need:
return 0

batch_size = batch.shape[0] * ws
batch_size = batch.shape[0]
end = min(batch_size, self.num_fake_need - self.num_fake_feeded)
if isinstance(batch, dict):
batch_to_feed = {k: v[:end, ...] for k, v in batch.items()}
else:
batch_to_feed = batch[:end, ...]

total_end = min(batch * ws,
self.num_real_need - self.num_real_feeded)
self.feed_op(batch_to_feed, mode)
self.num_fake_feeded += end
self.num_fake_feeded += total_end
return end
else:
raise ValueError(
Expand Down