Spaces:
Sleeping
Sleeping
File size: 1,547 Bytes
8b3e556 4b6071c 8b3e556 4b6071c 8b3e556 4b6071c 8b3e556 5edc626 8b3e556 5edc626 00598af |
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 56 57 58 59 60 |
from transformers import ViTImageProcessor, ViTForImageClassification
import torch
import gradio as gr
feature_extractor = ViTImageProcessor.from_pretrained("model_artifacts")
model = ViTForImageClassification.from_pretrained("model_artifacts")
labels = ['Chevrolet Equinox',
'Chevrolet Silverado 1500',
'Ford Escape',
'Ford Explorer',
'Ford F-150',
'GMC Sierra 1500',
'Honda CR-V',
'Jeep Compass',
'Jeep Grand Cherokee',
'Jeep Wrangler',
'Mazda CX-5',
'Nissan Rogue',
'RAM 1500',
'RAM 2500',
'Toyota Camry']
def classify(im):
features = feature_extractor(im, return_tensors='pt')
logits = model(features["pixel_values"])[-1]
probability = torch.nn.functional.softmax(logits, dim=-1)
probs = probability[0].detach().numpy()
confidences = {label: float(probs[i]) for i, label in enumerate(labels)}
return confidences
description = """
Simple car recognition model. Can recognize one of the followings:
Chevrolet Equinox
Chevrolet Silverado 1500
Ford Escape
Ford Explorer
Ford F-150
GMC Sierra 1500
Honda CR-V
Jeep Compass
Jeep Grand Cherokee
Jeep Wrangler
Mazda CX-5
Nissan Rogue
RAM 1500
RAM 2500
Toyota Camry
"""
interface = gr.Interface(fn=classify,
inputs="image",
outputs="label",
title="Car classification demo :)",
description=description )
interface.launch()
|