Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Object_Detection.ipynb +0 -0
- gradioapp.py +56 -0
- requirements.txt +6 -0
Object_Detection.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
gradioapp.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""gradioapp
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/1cD6eAJDAuLfS_1T9LE749-TpglGMtUq8
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
!pip install gradio
|
| 11 |
+
|
| 12 |
+
import gradio as gr
|
| 13 |
+
import tensorflow as tf
|
| 14 |
+
import numpy as np
|
| 15 |
+
from PIL import Image
|
| 16 |
+
import gdown
|
| 17 |
+
import os
|
| 18 |
+
|
| 19 |
+
# Load model
|
| 20 |
+
def load_model():
|
| 21 |
+
model_path = "resnet50_cifar10_model.h5"
|
| 22 |
+
if not os.path.exists(model_path):
|
| 23 |
+
url = "https://drive.google.com/uc?id=13KgM2DddlsscFQx4uoYK0lesSE6-DAo3"
|
| 24 |
+
gdown.download(url, model_path, quiet=False)
|
| 25 |
+
model = tf.keras.models.load_model(model_path)
|
| 26 |
+
return model
|
| 27 |
+
|
| 28 |
+
model = load_model()
|
| 29 |
+
|
| 30 |
+
class_names = ['Airplane', 'Automobile', 'Bird', 'Cat', 'Deer',
|
| 31 |
+
'Dog', 'Frog', 'Horse', 'Ship', 'Truck']
|
| 32 |
+
|
| 33 |
+
# Prediction function
|
| 34 |
+
def predict_cifar10(image):
|
| 35 |
+
image = image.convert("RGB")
|
| 36 |
+
img = image.resize((32, 32))
|
| 37 |
+
img_array = np.array(img) / 255.0
|
| 38 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 39 |
+
|
| 40 |
+
prediction = model.predict(img_array)
|
| 41 |
+
predicted_label = class_names[np.argmax(prediction)]
|
| 42 |
+
confidence = float(np.max(prediction)) * 100
|
| 43 |
+
|
| 44 |
+
return {predicted_label: confidence}
|
| 45 |
+
|
| 46 |
+
# Gradio Interface
|
| 47 |
+
iface = gr.Interface(
|
| 48 |
+
fn=predict_cifar10,
|
| 49 |
+
inputs=gr.Image(type="pil"),
|
| 50 |
+
outputs=gr.Label(num_top_classes=3),
|
| 51 |
+
title="🚀 CIFAR-10 Image Classifier using ResNet50",
|
| 52 |
+
description="Upload an image, and the model will classify it into one of the 10 CIFAR-10 classes."
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
iface.launch()
|
| 56 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
numpy
|
| 4 |
+
Pillow
|
| 5 |
+
gdown
|
| 6 |
+
opencv-python
|