将数据分为三个集test,train,validation
from sklearn.model_selection import train_test_split
(X_train, X_test, Y_train, Y_test) = train_test_split(X, Y, test_size=0.2, random_state=1)
from sklearn.model_selection import train_test_split
(X_train, Y_train, X_val, Y_val) = train_test_split(X_train, Y_train, test_size=0.3, random_state=1)
然后创建model
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(80, 80, 3)),
tf.keras.layers.Dense(512, activation='sigmoid'),
tf.keras.layers.Dense(2, activation='sigmoid')
])
编译model
model.compile(optimizer = 'adam',
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics = ['accuracy'])
然后Fit model 用 the training data 和 the validation data
model.fit(X_test, Y_test, epochs=100)
# Fits the model to the validation
model.fit(X_val, Y_val, epochs=100)
结果显示fit validation的时候,X_val, Y_val的数量不等
想请教一下是什么原因,我应该怎么实现fit validation