赞
踩
通过每个epoch,将数据划分为K等分,将K-1份作为训练集,其中1份作为验证集
代码如下(示例):
for epoch in range(50):
idx = tf.range(60000)
idx = tf.random.shuffle(idx)
x_train,y_train = tf.gather(x,idx[:50000]),tf.gather(y,idx[:50000])
x_val,y_val = tf.gather(x,idx[-10000:]),tf.gather(y,idx[-10000:])
db_train = tf.data.Dataset.from_tensor_slices((x_train,y_train))
db_train = db_train.map(preprocess).shuffle(50000).batch(batchsz)
db_val = tf.data.Dataset.from_tensor_slices((x_val,y_val))
db_val = db_train.map(preprocess).shuffle(10000).batch(batchsz)
network.fit(db_train_val,epochs= 50, validation_split = 0.1, validation_freq = 2)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。