MegEngine / Documentation

MegEngine Official Documentation
https://megengine.org.cn/doc/stable/zh/
Creative Commons Attribution Share Alike 4.0 International
39 stars 59 forks source link

plt.imshow( ) TypeError: Invalid shape for image data #235

Closed ZaccurLi closed 3 years ago

ZaccurLi commented 3 years ago

Document

https://github.com/MegEngine/Documentation/blob/main/source/getting-started/beginner/from-linear-regression-to-linear-classification.ipynb

Environment:

Issue&Solution


1. Issue

    plt_idx = i * num_classes + y + 1    
    plt.subplot(samples_per_class, num_classes, plt_idx)    
--->plt.imshow(train_data[idx], cmap="gray")    
    plt.axis('off')
    # ...
    TypeError: Invalid shape (28, 28, 1) for image data

Solution

    plt.imshow(train_data[idx].squeeze(), cmap="gray")

2. Issue

    idx = 28204 # 可以修改这个值
    plt.title("The label is: %s" % train_label[idx])
--->plt.imshow(train_data[idx], cmap="gray")
    plt.show()
    # ...
    TypeError: Invalid shape (28, 28, 1) for image data

Solution

    plt.imshow(train_data[idx].squeeze(), cmap="gray")

3. Issue

    plt.subplot(121)
    plt.axis('off')
    plt.title("Original Image:")
--->plt.imshow(original_image, cmap="gray")
    # ...
    TypeError: Invalid shape (3, 3, 1) for image data

Solution

    plt.imshow(original_image.squeeze(), cmap="gray")
cheekyshibe commented 3 years ago

感谢反馈,我们会在今天晚些时候更新。