Python 迭代模块列表时,索引超出范围';s序列
我正在写一个YOLO神经网络,我对它相当陌生。 我有一个用于定义网络的配置文件。它存储为Python 迭代模块列表时,索引超出范围';s序列,python,module,neural-network,pytorch,sequential,Python,Module,Neural Network,Pytorch,Sequential,我正在写一个YOLO神经网络,我对它相当陌生。 我有一个用于定义网络的配置文件。它存储为nn.ModuleList,其模块为nn.Sequential。 这些顺序的示例: (0): Sequential( (conv_0): Conv2d(3, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (batch_norm_0): BatchNorm2d(32, eps=1e-05, momentu
nn.ModuleList
,其模块为nn.Sequential
。
这些顺序的示例:
(0): Sequential(
(conv_0): Conv2d(3, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
(batch_norm_0): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(leaky_0): LeakyReLU(negative_slope=0.1, inplace=True)
)
(1): Sequential(
(conv_1): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)
(batch_norm_1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(leaky_1): LeakyReLU(negative_slope=0.1, inplace=True)
)
(2): Sequential(
(conv_2): Conv2d(64, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)
(batch_norm_2): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
(leaky_2): LeakyReLU(negative_slope=0.1, inplace=True)
)
然后我用它进行一些格式化,以使我的输出具有正确的形状,遍历ModuleList的每个模块
for i, module in enumerate(modules):
module_type = (module["type"])
if module_type == "convolutional" or module_type == "upsample":
x = self.module_list[i](x)
elif module_type == "route":
layers = module["layers"]
layers = [int(a) for a in layers]
if (layers[0]) > 0:
layers[0] = layers[0] - i
if len(layers) == 1:
x = outputs[i + (layers[0])]
else:
if (layers[1]) > 0:
layers[1] = layers[1] - i
map1 = outputs[i + layers[0]]
map2 = outputs[i + layers[1]]
x = torch.cat((map1, map2), 1)
elif module_type == "shortcut":
from_ = int(module["from"])
x = outputs[i-1] + outputs[i+from_]
elif module_type == 'yolo':
anchors = self.module_list[i][0].anchors
#Get the input dimensions
inp_dim = int (self.net_info["height"])
#Get the number of classes
num_classes = int (module["classes"])
#Transform
x = x.data
x = predict_transform(x, inp_dim, anchors, num_classes, CUDA)
if not write: #if no collector has been intialised.
detections = x
write = 1
else:
detections = torch.cat((detections, x), 1)
outputs[i] = x
但是,当我到达archors=self.module_列表[I][0].archors
行时,我得到一个错误,即索引0超出范围
我不知道为什么会发生这种情况。我尝试以不同的方式格式化模块列表的形状。
如果您有任何建议,我们将不胜感激。您显然没有提供全部信息!由于
(模块[“type”])
对于顺序模块无效!请提供一个MRE(最小可报告示例),以便更容易提供实际帮助