File size: 1,707 Bytes
fe6f0ef
 
eeaa8d0
 
fe6f0ef
eeaa8d0
 
fe6f0ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad7849a
b8fb8cf
ad7849a
b8fb8cf
ad7849a
b8fb8cf
fe6f0ef
 
ad7849a
fe6f0ef
 
 
b8fb8cf
 
fe6f0ef
 
5aab43b
ad7849a
 
fe6f0ef
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import tensorflow as tf
from huggingface_hub import from_pretrained_keras

# Load your trained models
model1 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")
model2 = from_pretrained_keras("ml-debi/EfficientNetB0-Food101")

with open('classes.txt', 'r') as f:
    classes = [line.strip() for line in f]

# Add information about the models
model1_info = """
### Model 1 Information

This model is based on the EfficientNetB0 architecture and was trained on the Food101 dataset.
"""

model2_info = """
### Model 2 Information

This model is based on the EfficientNetB0 architecture and was trained on augmented data, providing improved generalization.
"""

def preprocess(image):
    print("before resize", image.shape)
    image = tf.image.resize(image, [224, 224])
    
    image = tf.expand_dims(image, axis=0)
    print("After expanddims", image.shape)
    return image

def predict(model_selection, image):
    # Choose the model based on the dropdown selection
    model = model1 if model_selection == "EfficentNetB0 Fine Tune" else model2

    print(model.summary())

    image = preprocess(image)
    prediction = model.predict(image)
    print("model prediction", prediction)
    predicted_class = classes[int(tf.argmax(prediction, axis=1))]
    confidence = tf.reduce_max(prediction).numpy()
    return predicted_class, confidence

iface = gr.Interface(
    fn=predict,
    inputs=[gr.Dropdown(["EfficentNetB0 Fine Tune", "EfficentNetB0 Fine Tune Augmented"]), gr.Image()],
    outputs=[gr.Textbox(label="Predicted Class"), gr.Textbox(label="Confidence")],
    title="Transfer Learning Mini Project",
    description=f"{model1_info}\n\n{model2_info}",
)

iface.launch()