Upload 3 files
Browse files


- Gradio interface.py +29 -0
- Report.pdf +0 -0
- alexnet_cifar10.h5 +3 -0
Gradio interface.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import cv2
|
| 4 |
+
|
| 5 |
+
# Load the model
|
| 6 |
+
model = tf.keras.models.load_model(r"C:/Users/Irfan Arshad/Downloads/alexnet_cifar10.h5")
|
| 7 |
+
|
| 8 |
+
# Define a function to preprocess and predict using the loaded model
|
| 9 |
+
def predict(image):
|
| 10 |
+
# Resize image to (32, 32)
|
| 11 |
+
image = cv2.resize(image, (32, 32))
|
| 12 |
+
print("Resized image shape:", image.shape) # Print the shape of the resized image
|
| 13 |
+
# Convert image to float32 and normalize
|
| 14 |
+
image = image.astype('float32') / 255.0
|
| 15 |
+
# Add batch dimension
|
| 16 |
+
image = tf.expand_dims(image, 0)
|
| 17 |
+
# Predict using the model
|
| 18 |
+
prediction = model.predict(image)
|
| 19 |
+
class_index = tf.argmax(prediction, axis=1)[0].numpy()
|
| 20 |
+
class_label = class_names[class_index] # Get the class label
|
| 21 |
+
return class_label
|
| 22 |
+
|
| 23 |
+
# Define the class names for CIFAR-10
|
| 24 |
+
class_names = [
|
| 25 |
+
"airplane", "automobile", "bird", "cat", "deer",
|
| 26 |
+
"dog", "frog", "horse", "ship", "truck"
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
gr.Interface(fn=predict, inputs='image', outputs='text').launch()
|
Report.pdf
ADDED
|
Binary file (369 kB). View file
|
|
|
alexnet_cifar10.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:219ddb0d39b2c2e362f34fa41205b2c2ff5e7de15dadd6cd212e3a60c50ed695
|
| 3 |
+
size 259542304
|