reid-strong-baseline: Error on Test

Hi, I run the code for testing and got an error.

python3 tools/test.py --config_file='configs/softmax_triplet.yml' MODEL.DEVICE_ID "('0')" DATASETS.NAMES "('market1501')" MODEL.PRETRAIN_CHOICE "('self')" TEST.WEIGHT "('/media/user/DATA/reid-strong-baseline/log/resnet50_model_40.pth')"

File “tools/test.py”, line 61, in main model.load_param(cfg.TEST.WEIGHT) File “/media/user/DATA/reid-strong-baseline/modeling/baseline.py”, line 176, in load_param for i in param_dict: TypeError: ‘Baseline’ object is not iterable

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Hi. Unfortunately I have the same problem. Python 3.6.9 Pytorch 1.2.0 ignite 0.1.2

EDIT: solved by editing line 178 of baseline.py to: for i in param_dict.parameters(): # added .parameters() EDIT2: I was getting very poor performance (~1% acc on test vs ~95% acc reported after train) with the above hack so after some investigation that’s how the load_param function in baseline.py should actually look like:

    def load_param(self, trained_path):
        param_dict = torch.load(trained_path)
        for k, v in param_dict.state_dict().items():
            # print(i)
            if 'classifier' in k:
                # print(i[0])
                continue
            self.state_dict()[k].copy_(param_dict.state_dict()[k])

I have an similar error on test:

Traceback (most recent call last):
  File "tools/test.py", line 67, in <module>
    main()
  File "tools/test.py", line 61, in main
    model.load_param(cfg.TEST.WEIGHT)
  File "./modeling/baseline.py", line 176, in load_param
    for i in param_dict:
TypeError: 'Adam' object is not iterable

the problem occured because i used resnet50_optimizer_120.pth not resnet50_model_120.pth Hope it helps someone.

Now i have the same error like you

Traceback (most recent call last):
  File "tools/test.py", line 67, in <module>
    main()
  File "tools/test.py", line 61, in main
    model.load_param(cfg.TEST.WEIGHT)
  File "./modeling/baseline.py", line 176, in load_param
    for i in param_dict:
TypeError: 'Baseline' object is not iterable

I will try your solution

@deep0learning @TomKomar I have checked it. I did not encounter any bugs. (Python=1.0.0, Python=3.6.7, ignite=0.1.2)

I checked this recommendation, the problem persists. Do you have any other suggestions?

thank you reply. it is my fault.beacuse I can not find model . this is parameter problem. i solve it by understanding code carefully.

Thanks to the @TomKomar recommendation, changing load_param function in directory ./modeling/baseline.py to the following code solved the problem.

    def load_param(self, trained_path):
        param_dict = torch.load(trained_path)
        for k, v in param_dict.state_dict().items():
            # print(i)
            if 'classifier' in k:
                # print(i[0])
                continue
            self.state_dict()[k].copy_(param_dict.state_dict()[k])

@TomKomar just check it. Your solution is useful in pytorch 0.4.1. Good job !!!