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

docment GAN #72

Merged
merged 17 commits into from Mar 14, 2022
Merged

docment GAN #72

merged 17 commits into from Mar 14, 2022

Conversation

tmabraham
Copy link
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

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@tmabraham
Copy link
Collaborator Author

This PR would finish #20.

Copy link
Collaborator

@warner-benjamin warner-benjamin left a comment

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
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).

Copy link
Collaborator

@warner-benjamin warner-benjamin left a comment

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.

fastai/vision/gan.py Outdated Show resolved Hide resolved
fastai/vision/gan.py Outdated Show resolved Hide resolved
fastai/vision/gan.py Outdated Show resolved Hide resolved
tmabraham and others added 8 commits February 25, 2022 18:26
@tmabraham
Copy link
Collaborator Author

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

Copy link
Collaborator

@warner-benjamin warner-benjamin left a comment

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.

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

Copy link
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

fastai/vision/gan.py Outdated Show resolved Hide resolved
@@ -259,7 +316,12 @@ class InvisibleTensor(TensorBase):
def show(self, ctx=None, **kwargs): return ctx
Copy link
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?

fastai/vision/gan.py Show resolved Hide resolved
fastai/vision/gan.py Outdated Show resolved Hide resolved
fastai/vision/gan.py Outdated Show resolved Hide resolved
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
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
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
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
Collaborator

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

@tmabraham
Copy link
Collaborator Author

@warner-benjamin updated...

Copy link
Collaborator

@warner-benjamin warner-benjamin left a comment

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.

None yet

4 participants