【问题标题】:Preparing / Rendering Image for Image Classification with MNIST FASHION in Python在 Python 中使用 MNIST FASHION 为图像分类准备/渲染图像
【发布时间】:2021-06-05 09:48:06
【问题描述】:

我知道以前有人问过这个问题,但我仍然面临一些问题。

建立神经元网络并训练模型后,我现在想对我桌面上的图像进行分类。出于这个原因,图像必须在监督学习之前准备好……

如何将普通图片转换为 (1, 28, 28) 格式?

我试过这样做

Img = imageio.imread(f‘path/pic.png‘)
Image = numpy.expand(Img, 0)
Print(Image.shape) RETURNS (1, 28, 28, 3) and NOT (1, 28, 28)

任何想法,灵感,...... 提前致谢

【问题讨论】:

    标签: python python-3.x image rendering image-classification


    【解决方案1】:

    您可以使用 OpenCV,即 cv2 库(需要先安装),而不是使用 imageio 库。

    import numpy as np
    import cv2
    
    Img = cv2.imread('path/pic.png', 0)  # Need to pass in the zero as a flag to be read in gray-scale
    Image = np.expand_dims(Img, 0)
    print(Image.shape)
    
    > (1, m, n)
    

    【讨论】:

    • 太棒了,这是一个简单快捷的解决方案,Thx Omar ;)
    猜你喜欢
    • 2014-02-03
    • 1970-01-01
    • 2015-06-28
    • 2015-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    相关资源
    最近更新 更多