<jupyter_start><jupyter_text><jupyter_code>from google.colab import drive
drive.mount('/content/drive')
import tensorflow as tf
import numpy as np
from tensorflow import keras
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Flatten, Dropout
from tensorflow.keras.applications.resnet import preprocess_input
from tensorflow.keras.applications import xception
import pandas as pd
import PIL
import matplotlib.pyplot as plt
import os
import shutil<jupyter_output><empty_output><jupyter_text>Training<jupyter_code>train_datagen = keras.preprocessing.image.ImageDataGenerator(validation_split=0.2, preprocessing_function=preprocess_input)

train_generator = train_datagen.flow_from_directory(
        '/content/drive/My Drive/Module 2 shared folder/samples',
        subset="training",
        seed=3,
        target_size=(64, 64),
        batch_size=64,
        class_mode='categorical')

val_generator = train_datagen.flow_from_directory( '/content/drive/My Drive/Module 2 shared folder/samples', 
        subset="validation",
        seed=3,
        target_size=(64, 64),
        batch_size=64,
        class_mode='categorical')
train_datagen = keras.preprocessing.image.ImageDataGenerator(preprocessing_function=preprocess_input)

train_generator = train_datagen.flow_from_directory(
        '/content/drive/My Drive/Module 2 shared folder/samples',
        subset="training",
        seed=3,
        target_size=(64, 64),
        batch_size=64,
        class_mode='categorical')
resnet = keras.applications.ResNet50(include_top=False, pooling="max", input_shape=(64,64,3))
# mark loaded layers as not trainable
for layer in resnet.layers:
  layer.trainable = False 

data_augmentation = tf.keras.Sequential([
  keras.layers.experimental.preprocessing.RandomFlip("horizontal_and_vertical"),
  #keras.layers.experimental.preprocessing.RandomRotation(0.2),
])
# mark loaded layers as not trainable
#for layer in resnet.layers:
	#layer.trainable = False 

flat = Flatten()(resnet.layers[-1].output)
dense = Dense(1024, activation='relu')(flat)
output = Dense(5, activation='softmax')(dense)
model = Model(inputs=resnet.inputs, outputs=output)
model.summary()
model.compile(loss="categorical_crossentropy", optimizer=keras.optimizers.Adam(), metrics=["categorical_accuracy"])
checkpoint_best = keras.callbacks.ModelCheckpoint("/content/drive/My Drive/model_best.h5", 
            monitor='loss', verbose=0, save_best_only=True, save_weights_only=False, save_freq='epoch')
checkpoint = keras.callbacks.ModelCheckpoint("/content/drive/My Drive/model_last.h5", 
            verbose=0, save_best_only=False, save_weights_only=False, save_freq='epoch')
model.fit(
        train_generator,
        epochs = 5,
        validation_data=val_generator,
        callbacks=[checkpoint_best]
)
model.evaluate(val_generator)
model.fit(
        train_generator,
        initial_epoch=10,
        epochs = 20,
        validation_data=val_generator, callbacks=[checkpoint, checkpoint_best]
)
model.save("/content/drive/My Drive/model_best_64.h5")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1071657069737684, 'fraction_numerical': 0.01695457453614843, 'mean_word_length': 4.944866920152092, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '851', 'license': 'MIT', 'n_tokens_mistral': 1008, 'n_tokens_neox': 969, 'n_words': 174, 'path': 'RocksResnetTrainer.ipynb', 'repo_name': 'malcolmrite-dsi/RockVideoClassifier', 'size': '3126'}