python写人工智能的时候发现一个作用域的问题,为什么在for循环中的out_channels可以在return中是同一个,他不应该是一个局部变量吗?
def vgg(conv_arch):
conv_blks = []
in_channels = 1
for num_convs, out_channels in conv_arch:
conv_blks.append(vgg_block(num_convs, in_channels, out_channels))
in_channels = out_channels
return nn.Sequential(
*conv_blks, nn.Flatten(),
nn.Linear(out_channels * 7 * 7, 4096), nn.ReLU(),
nn.Linear(4096, 4096), nn.ReLU(),
nn.Linear(4096, 10)
)