-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Add examples to transform docs #1426
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
Conversation
- All "Transforms on torch.*Tensor" document their __call__ in a consistent manner and __call__ is shown in sphinx. - Fixed typos, punctuation, and naming. - Fixed wrong format of doc strings.
824a8fd to
fa9e946
Compare
Codecov Report
@@ Coverage Diff @@
## master #1426 +/- ##
==========================================
- Coverage 64.08% 63.97% -0.11%
==========================================
Files 80 80
Lines 6328 6343 +15
Branches 973 975 +2
==========================================
+ Hits 4055 4058 +3
- Misses 1986 1998 +12
Partials 287 287
Continue to review full report at Codecov.
|
fmassa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR @sotte!
I have a few comments, let me know what you think.
In particular, I'm thinking if we could just define the methods in the documentation somewhere, so that they do not live in the torchvision source.
|
Another thing, we should not forget to fix the random seeds (for both |
Report their input/output shapes.
The examples are only re-executed if the example code changes, i.e. calling |
|
We need to decide on the actual implementation of Just as reference: this is how skimage does it: |
I might not understand how matplotlib caching works, but I would have expected that if I clean up the build folder and re-run again
thanks for the pointers. I'm not yet clear if we want to have those functions in the torchvision distribution, but the pointers are anyway very helpful. I'm waiting on feedback from @jlin27 on what would be better. |
|
My vote is to keep _sample_image() private, given as you've all discussed, that it's specific for this example use case. Helps signal to users that they probably shouldn't be using it outside of this situation. As for where to store the images, I'd suggest a static folder with a descriptive name. For example, in pytorch/tutorials, images are stored /static/_img (https://github.com/pytorch/tutorials/tree/master/_static/images), and just make sure to double-check that they are pulled in properly during build. |
|
Seeds Private functions Loading and packaging the image / things that should be simple but are quite tricky def _sample_image():
"""Private helper function to load a sample PIL image.
This function might change and/or break. Don't depend on it.
"""
import os.path
from PIL import Image
data_dir = os.path.abspath(os.path.dirname(__file__))
return Image.open(os.path.join(data_dir, "assets", "grace_hopper_517x606.jpg"))Then of course we have to actually include the folder and change the # setup.py
setup(
...
zip_safe=False, # not zip safe because we load the image via a path
include_package_data=True,
)but after doing so I get the following error: I'm also not sure if we break things by making torchvision not The packaging problem is still not solved and I'm more than open for input! Ref |
|
Hi @sotte , Sorry for the delay in replying, I had to fix a few issues with torchvision lately (including making it About the error you are facing, from a quick search it might indicate that you might need to do a clean build for torchvision? Apart from that, I think that the approach you are following is the right one, with the I don't have much more experience with setuptools than that though |
|
@fmassa no worries and thanks for the pointer. I'll give it a try and get back to you. |
|
It's getting tricky :) Starting with a fresh build did not help. Here is a log of what I did: This yields the error: Checking
|
|
Just to verify that I did not break anything in my branch: on master cd17484 when adding |
The SOURCES.txt contained absolute paths which is not valid if you include_package_data. Therefore we switched to relpath.
|
@fmassa So I had to change the Please, anybody who is more knowledgeable with python packaging take a look at this! That being said, the PR should be complete now. Feel free to build the docs yourself and let me know if it's ok. |
|
@fmassa Please verify that it works on you end. If so I think we can merge this one (after rebasing). |
|
Hi @sotte Very sorry for the delay in coming back to you. I'll get this reviewed and merged tomorrow, thanks a lot! |
|
Absolutely no problem. Just let me know if you need anything else. |
|
@fmassa friendly ping :) Let me know what I can do to get this into masteri |
|
Very sorry for the delay @sotte! Was very busy working on a paper submission. I'm putting some time aside to review this tomorrow, thanks for the patience! |
vincentqb
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks good to me. The functions should definitely be private for now, since we can always decide to make them public at a later time.
The tests are failing to build though.
Building wheels for collected packages: torchvision
Building wheel for torchvision (setup.py) ... error
ERROR: Command errored out with exit status 1:
|
@fmassa I was not able to build when using |
This PR is the result of #1409. @fmassa thanks for the input!
The PR adds examples of each transform class to the sphinx docs. The result looks something like this:

Make
_sample_image()public@fmassa said:
I would argue that it's quite convenient to be able to get sample image and therefore
sample_image()should be public. skimage for example gives you quite a few sample images which I actually tend to use when using pytorch.(That being said I'm also fine with a private
_sample_image().)Implementation of
_sample_image()publicThe current implementation is just a dummy implementation that load the image from /tmp :)
The Hopper image is part of the
test/folder and is not part of the resulting egg/wheel/whatever.Normally I would just use https://docs.python.org/3.7/library/importlib.html#module-importlib.resources to load the file, but pytorch is not 3.7 only :) So we have to decide on where to put the file and how to load it. I'm no expert when it comes to packaging and I'm more than open for suggestion.
TODOs
_sample_image()really should de private_sample_image()depending on how the actual sample image is going to be shipped.__call__of TensorTransforms.Feedback welcome!
Closes #1409