Kaggle competition: Kannada MNIST
def call_model_efn() :
enet = efn.EfficientNetB7(
 input_shape=(512, 512, 3),
weights = 'noisy-student',
include_top=False 
)
 enet.trainable = True
model = tf.keras.Sequential([
enet,
tf.keras.layers.GlobalAveragePooling2D() ,
tf.keras.layers.Dense(len(CLASSES), activation='softmax')
 ])
 model.compile(
 optimizer='adam',
loss = 'sparse_categorical_crossentropy',
metrics=['sparse_categorical_accuracy'] 
)
 return model<train_model>
train_csv = pd.read_csv('/kaggle/input/Kannada-MNIST/train.csv')
 x_train = np.array(train_csv.iloc[:, 1:])
 y_train = to_categorical(train_csv.iloc[:, 0])
 x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
 x_train = x_train.astype(np.float32)
 x_train /= 255.0
y_train = y_train.astype(np.float32)
 print(x_train.shape)
 print(x_train.dtype)
 print(y_train.shape)
 print(y_train.dtype)
with strategy.scope() :
enet_model = call_model_efn()
enet_model.summary()
history_enet = enet_model.fit(
 get_training_dataset(load_dataset(TRAINING_FILENAMES),do_aug=False),
steps_per_epoch=STEPS_PER_EPOCH,
epochs=EPOCHS,
callbacks = [lr_callback],
validation_data = get_validation_dataset() ,
verbose=2 
)
<predict_on_test>
val_csv = pd.read_csv('/kaggle/input/Kannada-MNIST/Dig-MNIST.csv')
 x_val = np.array(val_csv.iloc[:, 1:])
 y_val = to_categorical(val_csv.iloc[:, 0])
 x_val = x_val.reshape(x_val.shape[0], 28, 28, 1)
 x_val = x_val.astype(np.float32)
 x_val /= 255.0
y_val = y_val.astype(np.float32)
 print(x_val.shape)
 print(x_val.dtype)
 print(y_val.shape)
 print(y_val.dtype )
cmdataset = get_validation_dataset(ordered=True)
 images_ds = cmdataset.map(lambda image, label: image)
 labels_ds = cmdataset.map(lambda image, label: label ).unbatch()
cm_correct_labels = next(iter(labels_ds.batch(NUM_VALIDATION_IMAGES)) ).numpy()
cm_probabilities = enet_model.predict(images_ds)
 cm_predictions = np.argmax(cm_probabilities, axis=-1)
 print("Correct labels: ", cm_correct_labels.shape, cm_correct_labels)
 print("Predicted labels: ", cm_predictions.shape, cm_predictions)
 cmat = confusion_matrix(cm_correct_labels, cm_predictions, labels=range(len(CLASSES)))
 score = f1_score(cm_correct_labels, cm_predictions, labels=range(len(CLASSES)) , average='macro')
 precision = precision_score(cm_correct_labels, cm_predictions, labels=range(len(CLASSES)) , average='macro')
 recall = recall_score(cm_correct_labels, cm_predictions, labels=range(len(CLASSES)) , average='macro')
 cmat =(cmat.T / cmat.sum(axis=1)).T
display_confusion_matrix(cmat, score, precision, recall)
 print('f1 score: {:.3f}, precision: {:.3f}, recall: {:.3f}'.format(score, precision, recall))<predict_on_test>