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

Throw ValueError for wrong reduction in losses #6604

Closed
oke-aditya opened this issue Sep 18, 2022 · 24 comments · Fixed by #6675
Closed

Throw ValueError for wrong reduction in losses #6604

oke-aditya opened this issue Sep 18, 2022 · 24 comments · Fixed by #6675

Comments

@oke-aditya
Copy link
Contributor

oke-aditya commented Sep 18, 2022

As discussed in #6457

The current problem

We do not restrict the reduction mode in losses. There are only three cases possible, ["none", "mean", "sum"]. If the user passes something like "xyz" we are not throwing any error or warning.

The solution

If users aren't passing one of the valid cases and using a random string instead. It's better to throw a ValueError suggesting them to use one of the correct choice.

We had thought of Enum based solution, but to keep better consistency with Pytorch core as discussed, we are adopting the above solution.

Edits required

Need to edit losses. which are namely
ciou_loss, diou_loss, giou_loss, and focal_loss

Also need to edit the relevant tests in test_ops.py

Additional Context

I think it's good first issue and some new contributor can take this 😃

Feel free to ping the maintainers or me if you need help. 😄

@NicolasHug
Copy link
Member

Looking at https://github.com/pytorch/vision/pull/6457/files, it looks like this is taken care of in the original PR already? Or were you referring to other losses @oke-aditya ?

@datumbox
Copy link
Contributor

I think @oke-aditya refers to all the other losses. I believe that's a good idea but if the ticket is intended for a new contributor, it's worth listing explicitly all the places were the change needs to happen and a potential idiom we want to adopt. This will help people who are not familiar with our code-base to pick it up.

@oke-aditya
Copy link
Contributor Author

Yeah I'm referring to all the other losses. I will add further details to help new contributors 😃

@oke-aditya
Copy link
Contributor Author

Well I hope I have edited the issue and explained it in bit more detail. I haven't given away the code of what needs to be done intentionally (as I believe some new contributor should try to figure out and interact with people while fixing)

cc @datumbox

@datumbox
Copy link
Contributor

@oke-aditya Looks great to me! Thanks for helping us attract more contributors :)

@adityagandhamal
Copy link
Contributor

I can work on this. Would you please assign me the task?

@oke-aditya
Copy link
Contributor Author

oke-aditya commented Sep 27, 2022

@adityagandhamal
feel free to send PR and ping me as a reviewer. I can review.

Also btw how did you come to know about this issue?

@adityagandhamal
Copy link
Contributor

I recently started using PyTorch and was browsing about, looking for anything to contribute to, and fortunately, I came upon this!

@datumbox
Copy link
Contributor

@adityagandhamal Welcome! I've assigned the ticket to you, looking forward to your PR!

@adityagandhamal
Copy link
Contributor

Yes. I've finished making the necessary changes to the code and am now working on the tests. Will send the PR soon.

@adityagandhamal
Copy link
Contributor

While running a test on test_giou_loss specifically, I am running into an error AttributeError: module 'torchvision.ops' has no attribute 'generalized_box_iou_loss'

Quite strange to have encountered such an error given the loss function exists in the module

@datumbox
Copy link
Contributor

This sounds weird. It seems like if TorchVision is not properly installed. I would start by a fresh conda environment and follow this guide. Let me know if you continue facing problems.

@adityagandhamal
Copy link
Contributor

Yes, I've been following the same guide but nonetheless, I'll go for it again.
But before I give another run at this, I'd like you to know that I did come across an error after running python setup.py develop. It was regarding Microsoft Visual C++ Build Tools. It kept on returning the same error even after installing the necessary package.

And pardon me if this sounds naive but one has to clone the forked repo into their local machine but in the guide, why is it mentioned to clone the parent repo? git clone https://github.com/pytorch/vision.git

@oke-aditya
Copy link
Contributor Author

I'd like you to know that I did come across an error after running python setup.py develop. It was regarding Microsoft Visual C++ Build Tools.

Can you send detailed log of the same? Sorry I can't help much as I use linux only.

but one has to clone the forked repo into their local machine but in the guide, why is it mentioned to clone the parent repo? git clone https://github.com/pytorch/vision.git

Yeah you need to clone the fork. The guide might be written to build from source and not to contribute.

@adityagandhamal
Copy link
Contributor

Okay, after spending some time on StackOverflow and rebooting the system, now it seems everything is good to go.
Finished processing dependencies for torchvision==0.14.0a0+30b879f

@oke-aditya @datumbox
I'll make the edits, run the tests, and ping you if needed.
Thank you

@adityagandhamal
Copy link
Contributor

Just to test whether torchvision is installed properly, I tried importing it only to get a windows popup error
Screenshot (854)

I can't figure this out

@oke-aditya
Copy link
Contributor Author

Actually you are doing quite a difficult thing. Building on windows. Much harder. WSL2 can help you though to make it easier.

Have you run

python setup.py develop ?

@oke-aditya
Copy link
Contributor Author

Also I believe we should have a step by step guide for windows @datumbox most of us don't probably use windows and it's a pain point for new developers to setup.

For Linux it's very very straightforward and hardly takes an hour.

@adityagandhamal
Copy link
Contributor

Have you run

python setup.py develop ?

Yes, I have. It ran without giving any error and returned Finished processing dependencies for torchvision==0.14.0a0+30b879f

@adityagandhamal
Copy link
Contributor

Yes, I agree that developing on WSL is always a better option.

On WSL as well, should the same steps be followed (according to the guide) as before?

@oke-aditya
Copy link
Contributor Author

Yeah WSL you can just install Ubuntu and follow the steps mentioned for Linux.
It will have gcc compiler and hence your half job will be done.

On WSL I believe you will need

  1. Install miniconda
  2. Create env and install Python
  3. Install pytorch nightly. For now cpuonly would suffice.
  4. clone torchvision. Follow the contribution guide

Basically 4 is

conda install libpng jpeg
python setup.py develop
pip install flake8 typing mypy pytest pytest-mock scipy

@adityagandhamal
Copy link
Contributor

WSL2 is great @oke-aditya! torchvision has successfully set up. No absurd errors so far.
Thank you

@oke-aditya
Copy link
Contributor Author

One of the nice things about good first issues is that it helps to understand what the difficulty a new contributor may face.

It's quite ok and in fact expected that a new contributor will need help in getting started and setting up. So nothing wrong about seeking help.

Keep going @adityagandhamal (btw our first name is the same 😃)

@adityagandhamal
Copy link
Contributor

@oke-aditya @datumbox
I have sent the PR, open to suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants