Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Pytorch 索引器:维度超出范围(预期在[-1,0]范围内,但得到2)_Pytorch - Fatal编程技术网

Pytorch 索引器:维度超出范围(预期在[-1,0]范围内,但得到2)

Pytorch 索引器:维度超出范围(预期在[-1,0]范围内,但得到2),pytorch,Pytorch,为什么在运行上述代码时会弹出以下错误 然后重新运行上面的代码 plt.imshow(torchvision.utils.make_grid(images[3], nrow=5).permute(1, 2, 0 ) --------------------------------------------------------------------------- IndexError Traceback (most recent

为什么在运行上述代码时会弹出以下错误

然后重新运行上面的代码

plt.imshow(torchvision.utils.make_grid(images[3], nrow=5).permute(1, 2, 0 )
  ---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-78-ce90d0e2159a> in <module>
----> 1 plt.imshow(torchvision.utils.make_grid(images[3], nrow=5).permute(1, 2, 0))

~\Anaconda3\lib\site-packages\torchvision\utils.py in make_grid(tensor, nrow, padding, normalize, range, scale_each, pad_value)
     74     xmaps = min(nrow, nmaps)
     75     ymaps = int(math.ceil(float(nmaps) / xmaps))
---> 76     height, width = int(tensor.size(2) + padding), int(tensor.size(3) + padding)
     77     num_channels = tensor.size(1)
     78     grid = tensor.new_full((num_channels, height * ymaps + padding, width * xmaps + padding), pad_value)

IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 2)
model= nn.Sequential(nn.Linear (150528, 1000), 
                     nn.ReLU(), 
                     nn.Linear(1000, 250) ,
                     nn.ReLU(),
                     nn.Linear(250, 32),
                     nn.LogSoftmax(dim=1),
                     )
criterion = nn.CrossEntropyLoss()
images = images.view(images.shape[0], -1)
logits = model (images)
loss = criterion(logits, labels)
print(loss)
plt.imshow(torchvision.utils.make_grid(images[3], nrow=5).permute(1, 2, 0 )