Acerca de TypeError: tipo no modificable: solución de error 'lista'

Encontré este error al escribir código en 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'

Motivo del error: debido a que el input_parameter en el código es una lista que almacena varias tuplas, el contenido es el siguiente:

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),
]

El error es "input_parameter(i)" . Al indexar los elementos de la lista, el valor del índice debe marcarse con corchetes en lugar de paréntesis. Simplemente cambie " input_parameter(i)" a "input_parameter[i]" .

Supongo que te gusta

Origin blog.csdn.net/qq_40641713/article/details/125500894
Recomendado
Clasificación