chrisdxie / uois

MIT License
145 stars 44 forks source link

TypeError: only integer tensors of a single element can be converted to an index #2

Closed bhazza closed 4 years ago

bhazza commented 4 years ago

When running uois_example.ipynb I get a "TypeError: only integer tensors of a single element can be converted to an index" when executing code block 7.

nvcc --version = Cuda compilation tools, release 10.0, V10.0.130

`Number of images: 9

/home//anaconda3/envs/uois/lib/python3.7/site-packages/torch/nn/functional.py:2494: UserWarning: Default upsampling behavior when mode=bilinear is changed to align_corners=False since 0.4.0. Please specify align_corners=True if the old behavior is desired. See the documentation of nn.Upsample for details. "See the documentation of nn.Upsample for details.".format(mode))


TypeError Traceback (most recent call last)

in 3 ### Compute segmentation masks ### 4 st_time = time() ----> 5 fg_masks, direction_predictions, initial_masks, seg_masks = tabletop_segmentor.run_on_batch(batch) 6 total_time = time() - st_time 7 print('Total time taken for Segmentation: {0} seconds'.format(round(total_time, 3))) ~/unseen_object_segmentation/uois/src/segmentation.py in run_on_batch(self, batch) 686 687 # Crop --> 688 rgb_crop = batch['rgb'][i, :, y_min:y_max+1, x_min:x_max+1] # [3 x crop_H x crop_W] 689 mask_crop = mask[y_min:y_max+1, x_min:x_max+1] # [crop_H x crop_W] 690 TypeError: only integer tensors of a single element can be converted to an index `
bhazza commented 4 years ago

It looks like pytorch was upgraded to version 1.3 in October, and so is now the default when creating the python environment using the command: conda env create -f env.yml Setting the pytorch version to 1.2 in env.yml fixes the issue. - pytorch=1.2

chrisdxie commented 4 years ago

@bhazza It seems that with PyTorch upgrading to version 1.3, torch.round() now returns a float as opposed to an int. A simple fix is to wrap lines 677-678 with Python's int() call.

chrisdxie commented 4 years ago

This has been fixed in 293926dd0468ff3f370eeb8badd02e7ea5e9682b