Make model
def build_model():
X = tf.keras.layers.Input(shape=[28, 28, 1])
H = tf.keras.layers.Conv2D(64, kernel_size=5, padding='same', activation='swish')(X)
H = tf.keras.layers.BatchNormalization()(H)
H = tf.keras.layers.Conv2D(64, kernel_size=5, padding='same', activation='swish')(H)
H = tf.keras.layers.MaxPool2D()(H)
H = tf.keras.layers.Conv2D(64, kernel_size=3, padding='same', activation='swish')(H)
H = tf.keras.layers.MaxPool2D()(H)
H = tf.keras.layers.Conv2D(64, kernel_size=3, padding='same', activation='swish')(H)
H = tf.keras.layers.MaxPool2D(pool_size=(2, 2), strides=(2, 2))(H)
H = tf.keras.layers.Dropout(0.3)(H)
H = tf.keras.layers.Flatten()(H)
H = tf.keras.layers.Dense(128)(H)
H = tf.keras.layers.BatchNormalization()(H)
H = tf.keras.layers.Activation('swish')(H)
H = tf.keras.layers.Dense(84)(H)
H = tf.keras.layers.Activation('swish')(H)
H = tf.keras.layers.Dropout(0.4)(H)
Y = tf.keras.layers.Dense(10, activation='softmax')(H)
model = tf.keras.models.Model(X, Y)
model.summary()
return model
model = build_model()
cross_val_score
from sklearn.model_selection import cross_val_score
scores = cross_val_score(model, x_train, y_train, cv=5)
Scores
import numpy as np
np.mean(scores)
print(scores)