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

Changing the number of classes #9

Open
aoussou opened this issue Mar 8, 2018 · 7 comments
Open

Changing the number of classes #9

aoussou opened this issue Mar 8, 2018 · 7 comments

Comments

@aoussou
Copy link

aoussou commented Mar 8, 2018

Hi there,

First, thanks a lot for the good work, it's really useful!

I am trying to train the model on 1 only one class (that class + background) using the code in resnet_34_8s_train.ipynb in a .py file . I am confident my dataset only has one class, so I change the number of class from 21 to 2, but I get the following error after when starting the first iteration:

RuntimeError: cuda runtime error (59) : device-side assert triggered at /opt/conda/conda-bld/pytorch_1518238441757/work/torch/lib/THC/generic/THCStorage.cu:58

I just wanted to make sure that for only 1 class, I should set number_of_classes = 2 instead of 21, and that you are able to make work with you home code work with a different number of classes? The full error is below:

  File "<ipython-input-1-574834e79b43>", line 1, in <module>
    runfile('/home/ft_fcnpt/pytorch-segmentation-detection-master/pytorch_segmentation_detection/recipes/pascal_voc/segmentation/py_version2.py', wdir='/home/john/ft_fcnpt/pytorch-segmentation-detection-master/pytorch_segmentation_detection/recipes/pascal_voc/segmentation')

  File "/home/anaconda3/envs/pt27/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "/home/anaconda3/envs/pt27/lib/python2.7/site-packages/spyder/utils/site/sitecustomize.py", line 94, in execfile
    builtins.execfile(filename, *where)

  File "/home/ft_fcnpt/pytorch-segmentation-detection-master/pytorch_segmentation_detection/recipes/pascal_voc/segmentation/py_version2.py", line 280, in <module>
    loss.backward()

  File "/home/anaconda3/envs/pt27/lib/python2.7/site-packages/torch/autograd/variable.py", line 167, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables)

  File "/home/anaconda3/envs/pt27/lib/python2.7/site-packages/torch/autograd/__init__.py", line 99, in backward
    variables, grad_variables, retain_graph)

  File "/home/anaconda3/envs/pt27/lib/python2.7/site-packages/torch/autograd/function.py", line 91, in apply
    return self._forward_cls.backward(self, *args)

  File "/home/anaconda3/envs/pt27/lib/python2.7/site-packages/torch/nn/_functions/thnn/upsampling.py", line 283, in backward
    grad_input = UpsamplingBilinear2dBackward.apply(grad_output, ctx.input_size, ctx.output_size)

  File "/home/anaconda3/envs/pt27/lib/python2.7/site-packages/torch/nn/_functions/thnn/upsampling.py", line 296, in forward
    grad_output = grad_output.contiguous()
@warmspringwinds
Copy link
Owner

Hi @nayriz . Thank you for reporting. That's a bug, change this line in your notebook:

logits_flatten = flatten_logits(logits, number_of_classes=21)

In your case, number_of_classes=2

Let me know if that works

@aoussou
Copy link
Author

aoussou commented Mar 9, 2018

Dear Daniil,

Thank you for your prompt reply. I had already changed that line. I have also changed the following lines:

fcn = resnet_dilated.Resnet34_8s(num_classes=2)

and

number_of_classes = 2

labels = range(number_of_classes)

Did you mean to say I should leave those unchanged and only change the line your mentioned?

Thanks alot!

@warmspringwinds
Copy link
Owner

Did that help to resolve your problem?
You should change everything related to number of classes.

Also check this file:
https://github.com/warmspringwinds/pytorch-segmentation-detection/blob/master/pytorch_segmentation_detection/recipes/endovis_2017/segmentation/resnet_18_8s_train.ipynb

It's a training file for a different dataset where we performed binary segmentation (similar to your problem).

@aoussou
Copy link
Author

aoussou commented Mar 9, 2018

I had already done that when I submitted the issue, so I guess it doesn't solve my problem.

Thank you for pointing out at the other notebook, I'll definitely have a look at it!

@warmspringwinds
Copy link
Owner

Great! Try it out.

Also bear in mind that your labels should be 0 and 1 (background and your class) in the
annotations and 255 for regions that you want to ignore.

and let me know if you need more help

@aoussou
Copy link
Author

aoussou commented Mar 9, 2018

Thanks a lot, when you say

your labels should be 0 and 1 (background and your class) in the annotations

you mean for the endovis files, right? For the Pascal Voc the labels should be the class number.

Also, it is possible to train the model with resnet_34_8s, right?

@warmspringwinds
Copy link
Owner

@nayriz I mean that depending on the number of classes in your own dataset
you should change all the related variables.

Yes, in Endovis we did it with 2 classes and I thought it might be easier for you as you
mentioned that your dataset has 2 classes. And yes, it is possible to do 2 classes with resnet_34

Sorry, the structure is a little bit messy so far -- I will change that in a future.

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

No branches or pull requests

2 participants