dangweili / pedestrian-attribute-recognition-pytorch

A simple baseline for pedestrian attribute recognition in surveillance scenarios
332 stars 80 forks source link

Changes required to run with python3 #28

Closed kHarshit closed 4 years ago

kHarshit commented 4 years ago

Hi, What changes are required to run the model in python3. So far, I've changed the cpickle instances to pickle

from import cPickle to pickle to import pickle

and added binary mode while reading and writing i.e. rb.

I've also changed the instances of has_key for dict to __contains__ inDeepMAR.py`.

I'm encountering the following error now:

cfg.__dict__
{'att_list': ['personalLess30',
              'personalLess45',
              'personalLess60',
              'personalLarger60',
              'carryingBackpack',
              'carryingOther',
              'lowerBodyCasual',
              'upperBodyCasual',
              'lowerBodyFormal',
              'upperBodyFormal',
              'accessoryHat',
              'upperBodyJacket',
              'lowerBodyJeans',
              'footwearLeatherShoes',
              'upperBodyLogo',
              'hairLong',
              'personalMale',
              'carryingMessengerBag',
              'accessoryMuffler',
              'accessoryNothing',
              'carryingNothing',
              'upperBodyPlaid',
              'carryingPlasticBags',
              'footwearSandals',
              'footwearShoes',
              'lowerBodyShorts',
              'upperBodyShortSleeve',
              'lowerBodyShortSkirt',
              'footwearSneaker',
              'upperBodyThinStripes',
              'accessorySunglasses',
              'lowerBodyTrousers',
              'upperBodyTshirt',
              'upperBodyOther',
              'upperBodyVNeck'],
 'demo_image': './dataset/demo/demo_image.png',
 'load_model_weight': True,
 'mean': [0.485, 0.456, 0.406],
 'model_kwargs': {'last_conv_stride': 2, 'num_att': 35},
 'model_weight_file': '/nfs/interns/kharshit/pedestrian-attribute-recognition-with-GCN/ckpt_epoch150.pth',
 'rand_seed': None,
 'resize': (224, 224),
 'set_seed': False,
 'std': [0.229, 0.224, 0.225],
 'sys_device_ids': (0,)}
------------------------------------------------------------
Traceback (most recent call last):
  File "script/experiment/demo.py", line 112, in <module>
    model = DeepMAR_ResNet50(**cfg.model_kwargs)
  File "/nfs/interns/kharshit/pedestrian-attribute-recognition-pytorch/baseline/model/DeepMAR.py", line 41, in __init__
    self.base = resnet50(pretrained=self.pretrained, last_conv_stride=self.last_conv_stride)
  File "/nfs/interns/kharshit/pedestrian-attribute-recognition-pytorch/baseline/model/resnet.py", line 189, in resnet50
    model.load_state_dict(remove_fc(model_zoo.load_url(model_urls['resnet50'])))
  File "/nfs/interns/kharshit/pedestrian-attribute-recognition-pytorch/baseline/model/resnet.py", line 151, in remove_fc
    for key, value in state_dict.items():
RuntimeError: OrderedDict mutated during iteration
kHarshit commented 4 years ago

Solved the problem by using list(state_dict.item()) in key deletion code in resnet.py.

iamdami commented 2 years ago

changed cPickle -> 'pickle', added binary mode when reading -> 'rb', when writing -> 'wb+'

this works for me on python3