moothes / ITSD-pytorch

code for CVPR 2020 paper "Interactive Two-Stream Decoder for Accurate and Fast Saliency Detection"
71 stars 10 forks source link

Trainer does not work #2

Open fu123456 opened 4 years ago

fu123456 commented 4 years ago

I run the train process, but it outputs errors as follows:

loading the settings Backbone: resnet, Using Gpu: 1

Traceback (most recent call last): File "train.py", line 10, in train() File "train.py", line 4, in train L = Loader('train') File "/ITSD-pytorch/src/Loader.py", line 54, in init self.loading(opt) File "/ITSD-pytorch/src/Loader.py", line 129, in loading self.Model = baseline(self.model, self.channel) TypeError: 'module' object is not callable

Please help me. How to solve it? Thx.

fu123456 commented 4 years ago

I have solved the above problem. But I have another error as follow:

loading the settings
Backbone: resnet, Using Gpu: 0
Traceback (most recent call last):
File "train.py", line 12, in <module>
train()
File "train.py", line 6, in train
L = Loader('train')
File "/home/user/**/ITSD-pytorch/src/Loader.py", line 56, in __init__
self.loading(opt)
File "/home/user/**/ITSD-pytorch/src/Loader.py", line 131, in loading
self.Model = baseline.baseline(self.model, self.channel) # fugang modify
File "/home/user/**/ITSD-pytorch/models/baseline.py", line 97, in __init__
self.encoder = Encoder(backbone, c)
File "/home/user/**/ITSD-pytorch/models/baseline.py", line 75, in __init__
self.encoder = resnet50(pretrained=True)
File "/home/user/**/ITSD-pytorch/models/encoder/resnet.py", line 114, in resnet
res.load_state_dict(torch.load('/home/user/**/ITSD-pytorch/PretrainModel/'+name+'.pkl', map_location='cpu'), strict=False) # use my absolute pkl file, fugang
File "/home/user/**/lib/python3.7/site-packages/torch/serialization.py", line 529, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/home/user/**/lib/python3.7/site-packages/torch/serialization.py", line 692, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 3: invalid start byte
moothes commented 4 years ago

Your pre-trained pkl file seems not suitable for our code. I can provide my pkl file to you, but it may take a couple of days. Or you can try other pre-trained weight.

fu123456 commented 4 years ago

Your pre-trained pkl file seems not suitable for our code. I can provide my pkl file to you, but it may take a couple of days. Or you can try other pre-trained weight.

Where can I download the other pkl file you said? I download the pkl file from the website, but it does not work. Can you tell me where can I download the pkl file that make your code do work?

fu123456 commented 4 years ago

Your pre-trained pkl file seems not suitable for our code. I can provide my pkl file to you, but it may take a couple of days. Or you can try other pre-trained weight.

It's better to provide a pkl file by the author, which ensures that the code does work.

panmyuan commented 4 years ago

Your pre-trained pkl file seems not suitable for our code. I can provide my pkl file to you, but it may take a couple of days. Or you can try other pre-trained weight.

It's better to provide a pkl file by the author, which ensures that the code does work.

hi,friend, i just use resnet50.pth to pretrain the model ,but the results are worse.

moothes commented 4 years ago

Sorry for this issue. I have uploaded my weight files to BaiduYun and the URLs are listed in readme file. Due to the coronavirus, it took me some time to reach the school server for these files.

fu123456 commented 4 years ago

Sorry for this issue. I have uploaded my weight files to BaiduYun and the URLs are listed in readme file. Due to the coronavirus, it took me some time to reach the school server for these files.

Very Thx. Your pkl file have overcome the above problem. But now I have another problem. When I run your train file, it output errors as follows:

loading the settings
Backbone: resnet, Using Gpu: 1
loading *** images from *** using time: 300.695s.
/home/user/anaconda3/lib/python3.7/site-packages/torch/nn/functional.py:
2973: UserWarning: Default upsampling behavior when mode=bilinear is cha
nged to align_corners=False since 0.4.0. Please specify align_corners=Tr
ue if the old behavior is desired. See the documentation of nn.Upsample
for details.
  "See the documentation of nn.Upsample for details.".format(mode))
  + Number of FLOPs: 15.92G
  + Number of params: 26.47M
using SGD
/home/user/anaconda3/lib/python3.7/site-packages/torch/optim/lr_schedule
r.py:123: UserWarning: Detected call of `lr_scheduler.step()` before `op
timizer.step()`. In PyTorch 1.1.0 and later, you should call them in the
 opposite order: `optimizer.step()` before `lr_scheduler.step()`.  Failu
re to do this will result in PyTorch skipping the first value of the lea
rning rate schedule. See more details at https://pytorch.org/docs/stable
/optim.html#how-to-adjust-learning-rate
  "https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rat
e", UserWarning)
------------------------------------------------------------------------
---

resnet | epoch 1:Traceback (most recent call last):
  File "train.py", line 12, in <module>
    train()
  File "train.py", line 9, in train
    TR.train()
  File "/home/user/***/ITSD-pytorch/src/Trainer.py", line 62, in train
    self.epoch(idx+1)
  File "/home/user/***/ITSD-pytorch/src/Trainer.py", line 41, in epoch
    X = torch.Tensor(batchs['X'], requires_grad=True).float().cuda(self.
Loader.ids[0])
TypeError: new() received an invalid combination of arguments - got (num
py.ndarray, requires_grad=bool), but expected one of:
 * (*, torch.device device)
      didn't match because some of the keywords were incorrect: requires
_grad
 * (torch.Storage storage)
 * (Tensor other)
 * (tuple of ints size, *, torch.device device)
 * (object data, *, torch.device device)

Notes: my torch version is 1.5.1. Can you help me again? Thx.

moothes commented 4 years ago

I run with pytorch version 0.4 or 1.0 is OK. From the error message, maybe you can try to replace the 'requires_grad' parameter to a torch.device type parameter.

fu123456 commented 4 years ago

Hi, what version your torchvision and torch are? Although I have install torch 0.4.1, It also output errors:

Traceback (most recent call last):
  File "train.py", line 3, in <module>
    from src import *
  File "/home/user/***/ITSD-pytorch/src/__init__.py", line 4, in <module
>
    from .Loader import *
  File "/home/user/***/ITSD-pytorch/src/Loader.py", line 10, in <module>
    from models import baseline
  File "/home/user/***/ITSD-pytorch/models/baseline.py", line 4, in <mod
ule>
    from models.encoder.resnet import resnet as resnet50
  File "/home/user/***/ITSD-pytorch/models/encoder/resnet.py", line 8, i
n <module>
    import torchvision.models as models
  File "/home/user/anaconda3/lib/python3.7/site-packages/torchvision/__i
nit__.py", line 3, in <module>
    from torchvision import models
  File "/home/user/anaconda3/lib/python3.7/site-packages/torchvision/mod
els/__init__.py", line 5, in <module>
    from .inception import *
  File "/home/user/anaconda3/lib/python3.7/site-packages/torchvision/mod
els/inception.py", line 6, in <module>
    from torch.jit.annotations import Optional
ImportError: cannot import name 'Optional' from 'torch.jit.annotations'
(/home/user/anaconda3/lib/python3.7/site-packages/torch/jit/annotations.
py)
moothes commented 4 years ago

File "/home/user/***/ITSD-pytorch/models/encoder/resnet.py", line 8, i n import torchvision.models as models

You can try to remove this line. It seems to have no effect on the code. My torch version 1.0.0, torchvision 0.2.1

fu123456 commented 4 years ago

Thx. I have installed torch (version 1.0.0) and torchvision (version 0.2.1). But the code also output errors:

loading the settings
Backbone: resnet, Using Gpu: 1
loading **** images from **** using time: ****s.
Traceback (most recent call last):
  File "train.py", line 12, in <module>
    train()
  File "train.py", line 6, in train
    L = Loader('train')
  File "/home/user/****/ITSD-pytorch/src/Loader.py", line 53, in __init__
    self.loading(opt)
  File "/home/user/****/ITSD-pytorch/src/Loader.py", line 126, in loading
    self.Model = baseline(self.model, self.channel)
TypeError: 'module' object is not callable

So, how to solve this problem? Very thx.

moothes commented 4 years ago

I have updated a new version code using official imagenet-pretrained weights. You can try the new one.