torchvision.datasets.ImageFolder 给了我一个 3x3 的图像网格,而不是 1 个图像
我不明白为什么它在 3x3 网格中给我 9 张灰色图像,而不是一张彩色图像(原始图像不是灰色的,有 RGB 通道)。我在这上面花了5个小时。感谢您的帮助。
这是我的代码
test_path = "asl_data/test/" #path to the folder
test_data = torchvision.datasets.ImageFolder(test_path, transform=torchvision.transforms.ToTensor())
def test32():
for x, y in test_data:
print(x.shape)
x = x.reshape(533,800,3)
plt.axis("off")
plt.imshow(x)
plt.show()
plt.axis("off")
plt.imshow(x[:176,:267,:])
break
test32()
I can't figure out why it's giving me 9 gray images in a 3x3 grid instead of just one color image (original image is not gray and has RGB channels). I have spent 5 hours on this. Thanks for the help.
Here is my code
test_path = "asl_data/test/" #path to the folder
test_data = torchvision.datasets.ImageFolder(test_path, transform=torchvision.transforms.ToTensor())
def test32():
for x, y in test_data:
print(x.shape)
x = x.reshape(533,800,3)
plt.axis("off")
plt.imshow(x)
plt.show()
plt.axis("off")
plt.imshow(x[:176,:267,:])
break
test32()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经典的。
您
重塑
而不是排列
。请参阅此帖子了解两者之间的关键区别。
修复:
一个简单的视觉示例:
Classic.
You
reshape
instead ofpermute
.See this thread on the crucial difference between the two.
Fix:
A simple visual example: