import gradio as gr import tensorflow as tf from tensorflow import keras from custom_model import ImageClassifier from resnet_model import ResNetClassifier from vgg16_model import VGG16Classifier from inception_v3_model import InceptionV3Classifier from mobilevet_v2 import MobileNetClassifier import os CLASS_NAMES =['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer', 'Dog', 'Frog', 'Horse', 'Ship', 'Truck'] # models custom_model = ImageClassifier() custom_model.load_model("image_classifier_model.h5") resnet_model = ResNetClassifier() vgg16_model = VGG16Classifier() inceptionV3_model = InceptionV3Classifier() mobilenet_model = MobileNetClassifier() def make_prediction(image, model_type="CNN (Custom)"): if "CNN (Custom)" == model_type: top_classes, top_probs = custom_model.classify_image(image, top_k=3) return {CLASS_NAMES[cls_id]:str(prob) for cls_id, prob in zip(top_classes, top_probs)} elif "ResNet50" == model_type: predictions = resnet_model.classify_image(image) return {class_name:str(prob) for _, class_name, prob in predictions} elif "VGG16" == model_type: predictions = vgg16_model.classify_image(image) return {class_name:str(prob) for _, class_name, prob in predictions} elif "Inception v3" == model_type: predictions = inceptionV3_model.classify_image(image) return {class_name:str(prob) for _, class_name, prob in predictions} elif "Mobile Net v2" == model_type: predictions = mobilenet_model.classify_image(image) return {class_name:str(prob) for _, class_name, prob in predictions} else: return {"Select a model to classify image"} def train_model(epochs, batch_size, validation_split): print("Training model") # Create an instance of the ImageClassifier classifier = ImageClassifier() # Load the dataset (x_train, y_train), (x_test, y_test) = classifier.load_dataset() # Build and train the model classifier.build_model(x_train) classifier.train_model(x_train, y_train, batch_size=int(batch_size), epochs=int(epochs), validation_split=float(validation_split)) # Evaluate the model classifier.evaluate_model(x_test, y_test) # Save the trained model print("Saving model ...") classifier.save_model("image_classifier_model.h5") custom_model = classifier def update_train_param_display(model_type): if "CNN (Custom)" == model_type: return [gr.update(visible=True), gr.update(visible=False)] return [gr.update(visible=False), gr.update(visible=True)] if __name__ == "__main__": # gradio gui app with gr.Blocks() as my_app: gr.Markdown("