<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Resnet Supervised Learning
This file trains a supervised learning model (Resnet50) using transfer learning to train on an unknown dataset. And the results give us a baseline accuracy to compare with the semi-supervised model (Mixmatch).
Step1:  Train on streetview_v3 dataset
Step2:  Train on streetview_v4 dataset
<ASSISTANT_TASK:>
Python Code:
from keras.utils import np_utils
import numpy as np
from resnet_lib import create_dataset, create_model, test_callback, tune_model, visualize_model
Explanation: Resnet Supervised Learning
This file trains a supervised learning model (Resnet50) using transfer learning to train on an unknown dataset. And the results give us a baseline accuracy to compare with the semi-supervised model (Mixmatch).
End of explanation
# Global constants
NUM_CLASSES = 2
IMAGE_SIZE = 64
BATCH_SIZE = 64
EPOCHS = 300
# Directories
INPUT_TF_TRAIN = '../Mixmatch/ML_DATA/streetview_v3_64-train.tfrecord'
INPUT_TF_TEST = '../Mixmatch/ML_DATA/streetview_v3_64-test.tfrecord'
# Construct the datsets
X_train, y_train = create_dataset(INPUT_TF_TRAIN)
X_test, y_test = create_dataset(INPUT_TF_TEST)
y_train = np_utils.to_categorical(y_train, NUM_CLASSES)
y_test = np_utils.to_categorical(y_test, NUM_CLASSES)
# Build model and fit the top layers
model = create_model((IMAGE_SIZE, IMAGE_SIZE, 3), NUM_CLASSES, lr=0.0001)
model.fit(x=X_train, y=y_train, epochs=EPOCHS, batch_size=BATCH_SIZE, verbose=1, validation_split = 0.005, validation_freq=1, callbacks=[test_callback((X_test, y_test))])
# Visualize the model and determine which block will be trained in the tuning phase
visualize_model(model)
# Fine tune the model
EPOCHS = 30
model = tune_model(model, trainable_layer=0, lr=0.0001)
model.fit(x=X_train, y=y_train, epochs=EPOCHS, batch_size=BATCH_SIZE, verbose=1, validation_split = 0.1, validation_freq=1, callbacks=[test_callback((X_test, y_test))])
# Output the predictions of a model to csv files for further analysis
pred = model.predict(X_test.astype(np.float32))
np.savetxt("results.csv", np.concatenate((y_test, pred), axis=1), delimiter=",")
Explanation: Train on streetview_v3 dataset
End of explanation
# Global constants
NUM_CLASSES = 2
IMAGE_SIZE = 64
BATCH_SIZE = 64
EPOCHS = 300
# Directories
INPUT_TF_TRAIN = '../Mixmatch/ML_DATA/streetview_v4_64-train.tfrecord'
INPUT_TF_TEST = '../Mixmatch/ML_DATA/streetview_v4_64-test.tfrecord'
# Construct the datsets
X_train, y_train = create_dataset(INPUT_TF_TRAIN, word_embeddings=True)
X_test, y_test = create_dataset(INPUT_TF_TEST, word_embeddings=True)
y_train = np_utils.to_categorical(y_train, NUM_CLASSES)
y_test = np_utils.to_categorical(y_test, NUM_CLASSES)
# Build model and fit the top layers
model = create_model((IMAGE_SIZE, IMAGE_SIZE, 4), NUM_CLASSES, lr=0.0001)
model.fit(x=X_train, y=y_train, epochs=EPOCHS, batch_size=BATCH_SIZE, verbose=1, validation_split = 0.005, validation_freq=1, callbacks=[test_callback((X_test, y_test))])
Explanation: Train on streetview_v4 dataset
End of explanation
<END_TASK>