在写神经网络的时候。经常见到将数据集reshape的操作,那么这个是什么意思呢,我查了一下,有下面的说法:
# X shape (60,000 28x28), y shape (10,000, ) (X_train, y_train), (X_test, y_test) = mnist.load_data() # data pre-processing X_train = X_train.reshape(X_train.shape[0], -1) / 255. # normalize ??
请问reshape这种写法什么含义? X_test = X_test.reshape(X_test.shape[0], -1) / 255. # normalize y_train = np_utils.to_categorical(y_train, num_classes=10) y_test = np_utils.to_categorical(y_test, num_classes=10)
X shape (60,000 28x28),表示输入数据 X 是个三维的数据,你可以理解为 60000行数据,每一行是一张28 x 28 的灰度图片。
题主是在用tensorflow做卷积神经网络入门的手写数字识别吧, 源码:x_image = tf.reshape(x, [-1, 28, 28, 1]) 这里是将一组图像矩阵x重建为新的矩阵,该新矩阵的维数为(a,28,28,1),其中-1表示a由实际情况来定。例如,x是一组图像的矩阵(假设是50张,大小为56×56),则执行 x_image = tf.reshape(x, [-1, 28, 28, 1]) 可以计算a=50×56×56/28/28/1=200。即x_image的维数为(200,28,28,1)。