Skip to content

docment GAN#72

Merged
warner-benjamin merged 17 commits into
masterfrom
docment_gan
Mar 14, 2022
Merged

docment GAN#72
warner-benjamin merged 17 commits into
masterfrom
docment_gan

Conversation

@tmabraham

Copy link
Copy Markdown
Collaborator

Okay here's my first docment PR, let me know if there are any issues and I would appreciate any feedback you have.

I'll note I did take out the after_epoch and show_img arguments since they weren't doing anything. I will take a little time to debug and get them working. Shall I make an issue in the main fastai repo? I can work on fixing that after the docment sprint.

@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@tmabraham

Copy link
Copy Markdown
Collaborator Author

This PR would finish #20.

Comment thread fastai/vision/gan.py Outdated

@warner-benjamin warner-benjamin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed on discord, added suggestions for one of the methods style issues. If you could fix the highlighted formatting issues from basic_generator in other methods, everything looks pretty good.

@tmabraham

Copy link
Copy Markdown
Collaborator Author

Finished the changes based on @warner-benjamin's and @muellerzr's suggestions.

I will note this very weird issue we discussed on Discord voice channel.

In the code there is the following function:

#export
def generate_noise(
    fn, # Dummy argument so it works with `DataBlock`
    size=100 # Size of returned noise vector
) -> InvisibleTensor: 
    "Generate noise vector."
    return cast(torch.randn(size), InvisibleTensor)

I have added some docmenting but not type annotations. However, once I specifically add a type annotation to size, the full notebook doesn't run without error anymore:

#export
def generate_noise(
    fn, # Dummy argument so it works with `DataBlock`
    size:int=100 # Size of returned noise vector
) -> InvisibleTensor: 
    "Generate noise vector."
    return cast(torch.randn(size), InvisibleTensor)

What happens is that generate_noise is used as get_x for a GAN DataBlock. The DataBlock functionality will pass a Path to generate_noise but it's a dummy argument and will return the noise vector as our x which is what we want. But when I add the type annotation, the Path becomes the x, as I discovered through dblock.summary.

This is a little concerning if code breaks due to the type annotations, so as a side note, we should all be making sure the tests pass for all of these PRs (must be enabled for first-time contributors).

@warner-benjamin warner-benjamin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed one formatting error. Made a couple suggestions to make the doc strings more concise. Please replicate those in the other doc strings. Also, I think the loss_crit doc string had an error, but am not 100% sure.

Comment thread fastai/vision/gan.py
Comment thread fastai/vision/gan.py
Comment thread fastai/vision/gan.py Outdated
tmabraham and others added 8 commits February 25, 2022 18:26
@tmabraham

Copy link
Copy Markdown
Collaborator Author

@warner-benjamin updated, let me know if there's anything else that needs to be updated...

@warner-benjamin warner-benjamin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to add a None type hint for args with a default of None. I provided an example.

Remove the None type hints and it looks good.

Comment thread fastai/vision/gan.py
Comment thread fastai/vision/gan.py Outdated
Comment thread fastai/vision/gan.py
@@ -121,23 +160,33 @@ def forward(self, output, target):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add types to AdaptiveLoss

Comment thread fastai/vision/gan.py Outdated
Comment thread fastai/vision/gan.py
@@ -259,7 +316,12 @@ class InvisibleTensor(TensorBase):
def show(self, ctx=None, **kwargs): return ctx

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add doc string to explain InvisibleTensor. What is Invisible about it?

Comment thread fastai/vision/gan.py
Comment thread fastai/vision/gan.py Outdated
Comment thread fastai/vision/gan.py Outdated
Comment thread fastai/vision/gan.py Outdated
switch_eval:bool=False, # Whether the model should be set to eval mode when calculating loss
**kwargs
):
"Create a WGAN from `dls`, `generator` and `critic`."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a WGAN? Is there a paper link or anything for this

@warner-benjamin

Copy link
Copy Markdown
Collaborator

One other thought, maybe the model training should be behind a nbdev #slow tag so we are not replicating it every time tests are run on GH Actions. Would also be preferred not to check in the UserWarnings to the documentation

tmabraham and others added 4 commits March 12, 2022 22:42
Co-authored-by: Kevin Bird <kevinbird15@gmail.com>
Co-authored-by: Kevin Bird <kevinbird15@gmail.com>
Co-authored-by: Kevin Bird <kevinbird15@gmail.com>
Co-authored-by: Kevin Bird <kevinbird15@gmail.com>
Co-authored-by: Kevin Bird <kevinbird15@gmail.com>
@tmabraham

Copy link
Copy Markdown
Collaborator Author

One other thought, maybe the model training should be behind a nbdev #slow tag so we are not replicating it every time tests are run on GH Actions. Would also be preferred not to check in the UserWarnings to the documentation

There is an all_slow tag at the top of the notebook so that's not needed. IDK about the UserWarnings though. Technically, there is a fastai PR to fix this which we can resolve after this sprint.

@warner-benjamin

Copy link
Copy Markdown
Collaborator

Alright. Resolve the CI errors and then it looks good to me.

@tmabraham

Copy link
Copy Markdown
Collaborator Author

@warner-benjamin updated...

@warner-benjamin warner-benjamin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@warner-benjamin warner-benjamin merged commit 9f21d3f into master Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants