isht7 / pytorch-deeplab-resnet

DeepLab resnet v2 model in pytorch
MIT License
602 stars 118 forks source link

TypeError: 'float' object cannot be interpreted as an integer #18

Closed mohitzsh closed 6 years ago

mohitzsh commented 6 years ago

Thanks for the amazing work. I am trying to use your model description for another segmentation problem.

But when I run

python train.py

this is the error log that I get.

Traceback (most recent call last): File "train.py", line 219, in images, label = get_data_from_chunk_v2(chunk) File "train.py", line 113, in get_data_from_chunk_v2 labels = [resize_label_batch(gt,i) for i in [a,a,b,a]] File "train.py", line 113, in labels = [resize_label_batch(gt,i) for i in [a,a,b,a]] File "train.py", line 65, in resize_label_batch label_resized = np.zeros((size,size,1,label.shape[3])) TypeError: 'float' object cannot be interpreted as an integer

Additional Info: I am running python 3.5

isht7 commented 6 years ago

Hi, this repo works with python 2.x, I have not tested it with python 3.x.

mohitzsh commented 6 years ago

Thanks for the reply! I’ll try with python 2.x.

Also, would it be okay if I ask you a few things about the implementation. I am trying to use your repo for adversarial training of semantic segmentation task and I am confused about a few things.

mohitzsh commented 6 years ago

It's working with python 2.7.

But I get a runtime error

THCudaCheckFAIL file=/opt/conda/conda-bld/pytorch_1501972792122/work/pytorch-0.1.12/torch/lib/THC/generic/THCTensorCopy.c line=18 error=59 : device-side assert triggered Traceback (most recent call last): File "train.py", line 227, in loss = loss + loss_calc(out[i+1],label[i+1],gpu0) File "train.py", line 128, in loss_calc label = Variable(label).cuda(gpu0) File "/home/sharm267/envs/pytorch-2.7/lib/python2.7/site-packages/torch/autograd/variable.py", line 243, in cuda return CudaTransfer(device_id, async)(self) File "/home/sharm267/envs/pytorch-2.7/lib/python2.7/site-packages/torch/autograd/_functions/tensor.py", line 160, in forward return i.cuda(async=self.async) File "/home/sharm267/envs/pytorch-2.7/lib/python2.7/site-packages/torch/_utils.py", line 65, in _cuda return newtype(self.size()).copy(self, async) RuntimeError: cuda runtime error (59) : device-side assert triggered at /opt/conda/conda-bld/pytorch_1501972792122/work/pytorch-0.1.12/torch/lib/THC/generic/THCTensorCopy.c:18

Any idea how I can handle this?

isht7 commented 6 years ago

this error occurs when this instruction(given in readme) is not followed - image how many labels are there in your data?

mohitzsh commented 6 years ago

I am using the PascalVOC dataset. That's why I assumed I can work with the default value of noLabels.

isht7 commented 6 years ago

to debug you could do this: print the max value of all labels for every batch. It should not be greater than 20, if you are using PASCAL VOC. In PASCAL VOC images, they have a background label, which is 255. I have merged it with background here.

isht7 commented 6 years ago

Let me know if you issue is solved, I will close this issue.

mohitzsh commented 6 years ago

I'll try to debug it tonight. I'll let you know how it goes.

mohitzsh commented 6 years ago

You were spot on. One of the images had a label value 192.

Thanks again for the work. :D

fabrizioschiano commented 2 years ago

hi, I am facing a similar issue, how do you check the number of labels of a ground truth image?