【发布时间】:2018-10-31 00:50:54
【问题描述】:
我的 npy 包含两个 ndarray,一个是 one-hot,另一个是标签。如何输入数据?
如何将这些数据转换成 x_train 作为张量?我只有 MNIST 数据集的经验,不需要处理输入数据。
【问题讨论】:
标签: numpy tensorflow
我的 npy 包含两个 ndarray,一个是 one-hot,另一个是标签。如何输入数据?
如何将这些数据转换成 x_train 作为张量?我只有 MNIST 数据集的经验,不需要处理输入数据。
【问题讨论】:
标签: numpy tensorflow
MNIST 数据集的加载方式与 .npy 数组类似。
这行代码
(X_train, y_train), (X_test, y_test) =
keras.datasets.mnist.load_data(path="C:/Users/476458/.keras/datasets/mnist.npz")
依次使用以下代码。
path = get_file(path,
origin='https://s3.amazonaws.com/img-datasets/mnist.npz',
file_hash='8a61469f7ea1b51cbae51d4f78837e45')
f = np.load(path)
x_train, y_train = f['x_train'], f['y_train']
x_test, y_test = f['x_test'], f['y_test']
f.close()
return (x_train, y_train), (x_test, y_test)
np.load 加载 .npz 文件,该文件是一个压缩存档,其中包含 4 个 .npy 文件(x_train.npy、y_train. npy, x_test.npy, y_test)。
但是您应该能够直接使用 np.load 加载 .npy 文件。
我希望这能给你一些想法。
【讨论】: