【发布时间】:2021-03-16 08:58:39
【问题描述】:
我正在使用 keras MNIST 数据集,其中包含 60k 图像的训练集和 10k 图像的测试集。在我的作业中,我被提示将训练集进一步拆分为 50k 用于训练和 10k 用于验证。我有点不确定如何执行此操作和/或处理此操作,因为我不必像以前那样将数据集拆分为特定数字。这是我到目前为止的代码:
import numpy as np
import scipy
import matplotlib.pyplot as plt
from keras.datasets import mnist
from util import func_confusion_matrix
# load (downloaded if needed) the MNIST dataset
(x_train, y_train), (x_test, y_test) = mnist.load_data()
# transform each image from 28 by28 to a 784 pixel vector
pixel_count = x_train.shape[1] * x_train.shape[2]
x_train = x_train.reshape(x_train.shape[0], pixel_count).astype('float32')
x_test = x_test.reshape(x_test.shape[0], pixel_count).astype('float32')
# normalize inputs from gray scale of 0-255 to values between 0-1
x_train = x_train / 255
x_test = x_test / 255
【问题讨论】:
标签: python tensorflow machine-learning keras dataset