【发布时间】:2020-04-19 18:19:10
【问题描述】:
我正在使用来自 TensorFlow 2.0 的 MNIST 数据集,并尝试用零填充它并将图像大小从 (28, 28, 1) 增加到 (32, 32, 1)。代码是:
# Load MNIST dataset-
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.mnist.load_data()
X_train.shape, y_train.shape
# ((60000, 28, 28), (60000,))
X_test.shape, y_test.shape
# ((10000, 28, 28), (10000,))
# Pad with 2 zeros on left and right hand sides-
X_train_padded = np.pad(X_train[:,], (2, 2), 'constant')
X_train_padded.shape
# (60004, 32, 32)
但是,上面使用的 'np.pad()' 函数并没有给我所需的 (6000, 32, 32) 形状,而且它返回的数组填充了零!而不是 X_train 中的原始值。
你能帮忙吗?
我正在使用 Python 3.8、TensorFlow 2.0 和 numpy 1.18。
谢谢!
【问题讨论】:
标签: python-3.x numpy tensorflow2.0