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 PGAN notebook #319

Merged
merged 3 commits into from
Apr 4, 2024
Merged
Changes from all commits
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
20 changes: 10 additions & 10 deletions nobrainer/processing/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from .base import BaseEstimator
from .. import losses
from ..dataset import get_dataset
from ..dataset import Dataset


class ProgressiveGeneration(BaseEstimator):
Expand Down Expand Up @@ -147,15 +147,17 @@ def _compile():
if batch_size % self.strategy.num_replicas_in_sync:
raise ValueError("batch size must be a multiple of the number of GPUs")

dataset = get_dataset(
dataset = Dataset.from_tfrecords(
file_pattern=info.get("file_pattern"),
batch_size=batch_size,
num_parallel_calls=num_parallel_calls,
volume_shape=(resolution, resolution, resolution),
n_classes=1,
scalar_label=True,
normalizer=info.get("normalizer") or normalizer,
scalar_labels=True,
)
n_epochs = info.get("epochs") or epochs
dataset.batch(batch_size).normalize(
info.get("normalizer") or normalizer
).repeat(n_epochs)

with self.strategy.scope():
# grow the networks by one (2^x) resolution
Expand All @@ -164,9 +166,7 @@ def _compile():
self.model_.discriminator.add_resolution()
_compile()

steps_per_epoch = (info.get("epochs") or epochs) // info.get(
"batch_size"
)
steps_per_epoch = n_epochs // info.get("batch_size")

# save_best_only is set to False as it is an adversarial loss
model_checkpoint_callback = tf.keras.callbacks.ModelCheckpoint(
Expand All @@ -182,7 +182,7 @@ def _compile():

print("Transition phase")
self.model_.fit(
dataset,
dataset.dataset,
phase="transition",
resolution=resolution,
steps_per_epoch=steps_per_epoch, # necessary for repeat dataset
Expand All @@ -191,7 +191,7 @@ def _compile():

print("Resolution phase")
self.model_.fit(
dataset,
dataset.dataset,
phase="resolution",
resolution=resolution,
steps_per_epoch=steps_per_epoch,
Expand Down
Loading