semantic-segmentation-pytorch icon indicating copy to clipboard operation
semantic-segmentation-pytorch copied to clipboard

pickle.UnpicklingError: invalid load key, '<'.

Open meteorshowers opened this issue 6 years ago • 5 comments

Hi I run into this error with your suggested environment: pickle.UnpicklingError: invalid load key, '<'..

Full log is as below:

 guest@Monster  ~/lxy/semantic-segmentation-pytorch   master  python3 train.py 
Input arguments:
batch_size_per_gpu 2
workers          16
start_epoch      1
ckpt             ./ckpt
lr_encoder       0.02
imgSize          [300, 375, 450, 525, 600]
id               baseline
disp_iter        20
deep_sup_scale   0.4
epoch_iters      5000
imgMaxSize       1000
lr_pow           0.9
root_dataset     ./data/
padding_constant 8
segm_downsampling_rate 8
beta1            0.9
random_flip      True
list_val         ./data/validation.odgt
fix_bn           0
weights_encoder  
arch_encoder     resnet50_dilated8
num_gpus         8
seed             304
weights_decoder  
num_epoch        20
optim            SGD
fc_dim           2048
lr_decoder       0.02
list_train       ./data/train.odgt
arch_decoder     ppm_bilinear_deepsup
num_class        150
weight_decay     0.0001
Model ID: baseline-resnet50_dilated8-ppm_bilinear_deepsup-ngpus8-batchSize16-imgMaxSize1000-paddingConst8-segmDownsampleRate8-LR_encoder0.02-LR_decoder0.02-epoch20-decay0.0001-fixBN0
Traceback (most recent call last):
  File "train.py", line 314, in <module>
    main(args)
  File "train.py", line 149, in main
    weights=args.weights_encoder)
  File "/home/guest/lxy/semantic-segmentation-pytorch/models/models.py", line 105, in build_encoder
    orig_resnet = resnet.__dict__['resnet50'](pretrained=pretrained)
  File "/home/guest/lxy/semantic-segmentation-pytorch/models/resnet.py", line 198, in resnet50
    model.load_state_dict(load_url(model_urls['resnet50']), strict=False)
  File "/home/guest/lxy/semantic-segmentation-pytorch/models/resnet.py", line 232, in load_url
    return torch.load(cached_file, map_location=map_location)
  File "/usr/local/lib/python3.5/dist-packages/torch/serialization.py", line 358, in load
    return _load(f, map_location, pickle_module)
  File "/usr/local/lib/python3.5/dist-packages/torch/serialization.py", line 532, in _load
    magic_number = pickle_module.load(f)
_pickle.UnpicklingError: invalid load key, '<'.

Detailed configuration:

  • Distribution:
uname -a 
Linux Monster 4.13.0-45-generic #50~16.04.1-Ubuntu SMP Wed May 30 11:18:27 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
  • Python
python3 --version
Python 3.5.2
  • Torch
python3 -c "import torch; print(torch.__version__)"
0.4.1

meteorshowers avatar Sep 12 '18 06:09 meteorshowers

Even i am having the same issue, anyone here can help me?

vjayd avatar Dec 26 '18 05:12 vjayd

I am having the same issue,too.Have you solved it yet?

liuwei941213 avatar May 22 '19 06:05 liuwei941213

I am having the same issue,too.Have you solved it yet? I am having the same issue,too.Have you solved it yet?

lyq893 avatar Dec 23 '19 10:12 lyq893

I also encountered the same problem, but in the end I found it was a problem with my network. You can check your internet connection.

onehahaha756 avatar Apr 10 '20 03:04 onehahaha756

This error is caused by loading the wrong model file (*.pth). When you import backbone network files ( for example in this issue) ——

semantic-segmentation-pytorch/mit_semseg/models/resnet.py

Line 11-15 in this py file gives the url of Resnet models to download: model_urls = { 'resnet18': 'http://sceneparsing.csail.mit.edu/model/pretrained_resnet/resnet18-imagenet.pth', 'resnet50': 'http://sceneparsing.csail.mit.edu/model/pretrained_resnet/resnet50-imagenet.pth', 'resnet101': 'http://sceneparsing.csail.mit.edu/model/pretrained_resnet/resnet101-imagenet.pth' } If your computer fails to download these pth files, it will return some html files begins with '<' (which becomes the error you got)

Solution: download those pth files, and put them in the folder (model_dir) given by

semantic-segmentation-pytorch/mit_semseg/models/utils.py

line 10 :def load_url(url, model_dir='./pretrained', map_location=None):

changesome avatar Oct 30 '21 06:10 changesome