原理
- 在深度学习中,为了防止过拟合,被切分出来的验证集用来停止训练,但木有用于训练而导致浪费
- 本文尝试训练集停止训练后,验证集加入训练,并用多组参数进行实验
Python极简算法
图像识别示例
from keras.datasets import cifar10
from keras.utils import to_categorical
from keras.models import Sequential
from keras.layers import Dense, Flatten, Conv2D, MaxPooling2D
from keras.callbacks import EarlyStopping
from sklearn.model_selection import train_test_split
verbose = 2
batch_size = 256
patience = 1
callbacks = [EarlyStopping('val_acc', patience=patience)]
(x1, y1), (x2, y2) = cifar10.load_data()
x1, x2 = x1 / 255, x2 / 255
y1 = to_categorical(y1, 10)
y2 = to_categorical(y2, 10)
def experiment(validation_size=.1):
x11, x12, y11, y12 = train_test_split(x1, y1, test_size=validation_size)
model = Sequential()
for i in (32, 64):
model.add(Conv2D(i, (3, 3), padding=