File size: 978 Bytes
d9d52b8
 
 
 
 
 
 
 
 
 
 
6ec9af6
d9d52b8
 
 
 
 
 
 
 
 
 
ab45519
d9d52b8
f2228d5
 
 
 
 
 
 
 
67208d8
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

# AUTOGENERATED! DO NOT EDIT! File to edit: Train_class.ipynb.

# %% auto 0
__all__ = ['model', 'cat', 'image', 'label', 'eg', 'classify_vehicle']

# %% Train_class.ipynb 1
from fastai.vision.all import *
import gradio as gr

# %% Train_class.ipynb 2
model = load_learner('train_model.pkl')

# %% Train_class.ipynb 3
cat = ('Bus','Train')
def classify_vehicle(img):
    pred, idx, probs = model.predict(img)
    return dict(zip(cat, map(lambda x: f"{float(x):.7f}", probs)))

# %% Train_class.ipynb 8
image = gr.Image()
label = gr.Label()
#eg = ['train.jpg','bike.jpg','bus.jpg','car.jpeg']

gr.Interface(
    fn=classify_vehicle,
    inputs=image,
    outputs=label,
    title="Vehicle Classifier",
    description="This application classifies images of vehicles into two categories: Bus and Train. Upload an image of a vehicle, and the model will predict whether it is a Bus or a Train. The app will display the probabilities for each category."
    
).launch(inline=False)