【问题标题】:Image plotting - after processing图像绘图 - 处理后
【发布时间】:2015-12-04 13:47:23
【问题描述】:

我正在研究用于深度学习的 Keras 包,并在 https://github.com/fchollet/keras/blob/master/examples/cifar10_cnn.py 上找到了一个很好的代码示例,它很好地集成了图像预处理(例如旋转和移位)。我想知道 - 在预处理后是否可以轻松绘制训练图像以观察这些旋转和移位的影响?

【问题讨论】:

    标签: keras


    【解决方案1】:

    您可以通过将save_to_dir='path_to_dir' 传递给数据生成器的flow() 函数来将生成的图像保存到磁盘。

    【讨论】:

      【解决方案2】:

      是的,可以绘制图像。以 MNIST 数据集为例:

      from keras.datasets import mnist
      from keras.preprocessing.image import ImageDataGenerator
      from matplotlib import pyplot
      
      (X_train, y_train), (X_test, y_test) = mnist.load_data()
      
      X_train = X_train.reshape(X_train.shape[0], 1, 28, 28)
      X_test = X_test.reshape(X_test.shape[0], 1, 28, 28)
      
      X_train = X_train.astype('float32')
      X_test = X_test.astype('float32')
      
      datagen = ImageDataGenerator(horizontal_flip=True, vertical_flip=True)
      
      datagen.fit(X_train)
      
      for X_batch, y_batch in datagen.flow(X_train, y_train, batch_size=9):
      # grid of 3x3 images
          for i in range(0, 9):
              pyplot.subplot(330 + 1 + i)
              pyplot.imshow(X_batch[i].reshape(28, 28), cmap=pyplot.get_cmap('gray'))
      
          pyplot.show()
          break
      

      更多详情请参考this链接。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-20
        • 1970-01-01
        • 2020-02-24
        • 1970-01-01
        • 2021-02-13
        • 1970-01-01
        相关资源
        最近更新 更多