【问题标题】:Stacking multiple RGB images in numpy array for CNN implementation在 numpy 数组中堆叠多个 RGB 图像以实现 CNN
【发布时间】:2019-10-05 12:19:32
【问题描述】:

我有 1000 张 RGB 图像,我想从当前目录中读取这些图像并将其存储在 (1000,3,32,32) 形状的 numpy 数组中,以便在 CNN 中使用。

出于这个原因,我阅读了一个示例图像,将其大小调整为 32 * 32。然后将其附加到我使用形状 (1000,3,32,32) 的零创建的数组“a”中。但是我收到一个名为“'numpy.ndarray'一个对象没有属性'append'”的错误。如何解决?如果它需要任何不同的方法,我也愿意。

import matplotlib.pyplot as plt

import numpy as np

reshapedimage =cv2.resize(cv2.imread("0 (1).png", 1), (32, 32))


a = np.zeros((1000,3,32,32))

a.append(reshapedimage)

【问题讨论】:

    标签: python-3.x image deep-learning google-colaboratory


    【解决方案1】:

    我认为你的意思是:

    import numpy as np
    
    # Create dummy image-like thing
    w, h = 32, 32
    im=np.arange(h*w*3).reshape((3,h,w))                                                       
    
    # Create empty list
    stack=[]                                                                                   
    
    # Append the image to the stack 5 times
    stack.append(im)
    stack.append(im)
    stack.append(im)
    stack.append(im)
    stack.append(im)                                                                          
    
    # Make Numpy array and check size                                                        
    v = np.array(stack)                                                                        
    print(v.shape)                                                                                    
    

    输出

    (5, 3, 32, 32)
    

    【讨论】:

      猜你喜欢
      • 2017-10-01
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-05
      • 1970-01-01
      • 2016-08-26
      相关资源
      最近更新 更多