kmaninis / OSVOS-PyTorch

PyTorch implementation of One-Shot Video Object Segmentation (OSVOS)
http://vision.ee.ethz.ch/~cvlsegmentation/osvos
GNU General Public License v3.0
564 stars 106 forks source link

net visualisation results in RuntimeError #11

Closed yiminglin-ai closed 6 years ago

yiminglin-ai commented 6 years ago

Hi, I set the variable vis_net to 1 and run train_online.py but the following errors came out:

Constructing OSVOS architecture..
Initializing weights..
Traceback (most recent call last):
  File "train_online.py", line 72, in <module>
    y = net.forward(x)
  File "/home/yiming/projects/OSVOS-PyTorch/networks/vgg_osvos.py", line 61, in forward
    x = self.stages[0](x)
  File "/home/yiming/projects/miniconda3/envs/pt3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yiming/projects/miniconda3/envs/pt3/lib/python3.6/site-packages/torch/nn/modules/container.py", line 91, in forward
    input = module(input)
  File "/home/yiming/projects/miniconda3/envs/pt3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 491, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/yiming/projects/miniconda3/envs/pt3/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 301, in forward
    self.padding, self.dilation, self.groups)
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

I think the following line should be put before visualisation. net.to(device) # PyTorch 0.4.0 style

Nice work!

kmaninis commented 6 years ago

Hi,

Thanks for pointing this out. Forgot to port that part of the code :) It should be fixed now. Thanks a lot again.

yiminglin-ai commented 6 years ago

You're welcome. I also found that if you've got multiple GPUs and set gpu_id to 1, the code will still take around 500MB on GPU 0. I suppose this comes from the line net.load_state_dict which first loads the CudaTensors to GPU0 and then moves to GPU1. I tried several ways to free the 500 MB but none worked. It may be a bug from PyTorch itself but if you happen to know a solution to this please let me know :).

scaelles commented 6 years ago

I had the same problem that the code loads 500MB in GPU 0. The workaround that I have found for now is using the following:

os.environ["CUDA_VISIBLE_DEVICES"] = str(gpu_id)
device = torch.device("cuda:" + str(0) if torch.cuda.is_available() else "cpu")