<jupyter_start><jupyter_text>Build the model (Transfer VGG19 - Fine Tuning)<jupyter_code>rescale = tf.keras.applications.vgg19.preprocess_input
base_model = tf.keras.applications.VGG19(input_shape=(256,256,3),include_top=False,weights="imagenet")
base_model.trainable = True

for layer in base_model.layers:
    if layer.name == "block3_pool":
        break
    layer.trainable = False

class Transfer_VGG19():
    def model(self,input):
        self.x = rescale(input)
        self.x = base_model(self.x,training=False)
        self.x = tf.keras.layers.GlobalAveragePooling2D()(self.x)
        self.x = tf.keras.layers.Flatten()(self.x)
        self.x = tf.keras.layers.Dense(128,activation="relu")(self.x)
        self.x = tf.keras.layers.Dropout(0.2,seed=42)(self.x)
        self.x = tf.keras.layers.Dense(64,activation="relu")(self.x)
        self.x = tf.keras.layers.Dropout(0.2,seed=42)(self.x)
        self.output = tf.keras.layers.Dense(3,activation="softmax")(self.x)
        self.model = tf.keras.Model(input,self.output,name="Transfer_VGG19")
        return self.model

TFVGG19 = Transfer_VGG19()
model = TFVGG19.model(tf.keras.Input(shape=(256,256,3)))
model.summary()
model.compile(tf.keras.optimizers.RMSprop(1e-5),tf.keras.losses.CategoricalCrossentropy(),metrics=["accuracy"])
if __name__=="__main__":
    checkpoint = tf.keras.callbacks.ModelCheckpoint("makerere.h5",save_weights_only=False,save_best_only=True)
    model.fit(train_ds,epochs=10,validation_data=val_ds,callbacks=[checkpoint])
    best = tf.keras.models.load_model("makerere.h5")
    val_loss,val_acc = best.evaluate(val_ds)
    print("\nVal Accuracy: {:.2f} %".format(100*val_acc))
    print("Val Loss: {:.2f} %".format(100*val_loss))<jupyter_output>Epoch 1/10
98/98 [==============================] - 98s 837ms/step - loss: 0.6550 - accuracy: 0.7469 - val_loss: 0.2431 - val_accuracy: 0.9219
Epoch 2/10
98/98 [==============================] - 69s 700ms/step - loss: 0.2533 - accuracy: 0.9098 - val_loss: 0.1204 - val_accuracy: 0.9641
Epoch 3/10
98/98 [==============================] - 69s 703ms/step - loss: 0.1425 - accuracy: 0.9514 - val_loss: 0.1117 - val_accuracy: 0.9654
Epoch 4/10
98/98 [==============================] - 69s 705ms/step - loss: 0.0950 - accuracy: 0.9661 - val_loss: 0.0826 - val_accuracy: 0.9718
Epoch 5/10
98/98 [==============================] - 70s 708ms/step - loss: 0.0781 - accuracy: 0.9773 - val_loss: 0.0528 - val_accuracy: 0.9795
Epoch 6/10
98/98 [==============================] - 70s 714ms/step - loss: 0.0532 - accuracy: 0.9818 - val_loss: 0.0578 - val_accuracy: 0.9808
Epoch 7/10
98/98 [==============================] - 70s 708ms/step - loss: 0.0475 - accuracy: 0.9850 - val_loss: 0.0605 - val_accuracy: 0.9834[...]
{'fraction_non_alphanumeric': 0.22534696859021183, 'fraction_numerical': 0.10372534696859022, 'mean_word_length': 4.167924528301887, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '218172', 'license': 'MIT', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1042, 'n_words': 161, 'path': 'VGG19/vgg19.ipynb', 'repo_name': 'AndryRafam/Makerere', 'size': '2738'}