在用python写代码遇到了这个错误:
File "/home/dwt/MyCode/pycharm_projects/YOLOX/yolox/models/darknet_search.py", line 196, in <listcomp>
self.dark3 = nn.Sequential(*[PRIMITIVES[block_names[i]](*input_parameter(i))
│ │ │ │ │ └ 4
│ │ │ │ └ 4
│ │ │ └ [['ir_k3_e3'], ['ir_k3_e6'], ['ir_k3_e6'], ['ir_k3_e6'], ['ir_k3_e6'], ['ir_k5_e1'], ['ir_k3_e6'], ['skip'], ['ir_k5_s2'], ['...
│ │ └ {'skip': <function <lambda> at 0x7f9069d7a9d0>, 'ir_k3': <function <lambda> at 0x7f9069d7aa60>, 'ir_k5': <function <lambda> a...
│ └ <class 'torch.nn.modules.container.Sequential'>
└ <module 'torch.nn' from '/home/dwt/anaconda3/envs/fbnet_yolox/lib/python3.8/site-packages/torch/nn/__init__.py'>
TypeError: unhashable type: 'list'
报错原因:是因为代码中input_parameter是一个储存若干元组的列表,内容如下:
input_parameter = [
(32, 64, -999, 2), (64, 64, -999, 1), (64, 64, -999, 1), (64, 64, -999, 1),
(64, 128, -999, 2), (128, 128, -999, 1), (128, 128, -999, 1), (128, 128, -999, 1),
(128, 256, -999, 2), (256, 256, -999, 1), (256, 256, -999, 1), (256, 256, -999, 1),
(256, 512, -999, 2), (256, 512, -999, 1), (256, 512, -999, 1), (256, 512, -999, 1),
]
而错误之处是“input_parameter(i)”,对列表中元素索引时,应该用中括号标记索引值,而不是小括号。将“input_parameter(i)”改为“input_parameter[i]”即可。