| import gradio as gr |
| import tensorflow as tf |
| print(tf.__version__) |
| import numpy as np |
| from PIL import Image |
| |
| model_path = "vehicles_transferlearning_nasnetlarge.keras" |
| model = tf.keras.models.load_model(model_path) |
| |
| |
| def predict_vehicles(image): |
| |
| print(type(image)) |
| image = Image.fromarray(image.astype('uint8')) |
| image = image.resize((150, 150)) |
| image = np.array(image) |
| image = np.expand_dims(image, axis=0) |
| |
| |
| prediction = model.predict(image) |
| |
| |
| |
| prediction = np.round(prediction, 2) |
| |
| |
| p_car = prediction[0][0] |
| p_motorcycle = prediction[0][1] |
| p_truck = prediction[0][2] |
| |
| return {'car': p_car, 'motorcycle': p_motorcycle, 'truck': p_truck} |
| |
| |
| |
| input_image = gr.Image() |
| iface = gr.Interface( |
| fn=predict_vehicles, |
| inputs=input_image, |
| outputs=gr.Label(), |
| examples=["Sample_images/sample1.png", "Sample_images/sample2.jpg", "Sample_images/sample3.jpg", "Sample_images/sample4.jpg", "Sample_images/sample5.jpg", "Sample_images/sample6.jpg"], |
| description="TEST.") |
| |
| iface.launch() |