【发布时间】:2020-02-25 20:12:17
【问题描述】:
我尝试使用带有 Keras 的 Alexnet 的 MNIST 数据集,所以我应该改变维度(因为 MNIST 是灰度的,Alexnet 需要是 RGB 并且也是 227*227)。现在我得到了一些结果,numpy_imgs=(10,227,227,1) 但我应该像(10,227,227,3) 那样做,你可以在我的代码中看到我之前所做的,
谢谢。
import tensorflow as tf
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
batch=mnist.train.next_batch(10)
X_batch = batch[0]
batch_tensor = tf.reshape(X_batch, [10, 28, 28, 1])
resized_images = tf.image.resize_images(batch_tensor, [227,227])
with tf.Session() as sess:
numpy_imgs = resized_images.eval(session=sess) # mnist images converted to numpy array
r2=[]
t=list(numpy_imgs)
dim = np.zeros((227,227))
for i in range(0,10):
R=np.stack((t[i],dim,dim),axis=2)
R=list(R)
r2.append(R)
y3=np.asarray(r2)
我在下面尝试了一些方法,但出现了“ValueError:所有输入数组必须具有相同的形状”之类的错误,我该如何解决?
【问题讨论】:
标签: python tensorflow deep-learning image-resizing mnist