File size: 1,677 Bytes
4d9f8c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab3d24a
4d9f8c5
 
 
 
ab3d24a
5dc1c75
 
 
 
 
 
 
 
 
 
ec980de
5dc1c75
d85088c
4d9f8c5
 
 
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
from transformers import ViTImageProcessor, ViTForImageClassification
import torch
import gradio as gr

feature_extractor = ViTImageProcessor.from_pretrained("car_scene_model")
model = ViTForImageClassification.from_pretrained("car_scene_model")

labels = ['Exterior', 'Interior', 'Unknown']

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 = """
Car scene recognition demo. Upload or drag a .jpg image to test
        """
interface = gr.Interface(fn=classify,
                         inputs="image",
                         outputs="label",
                         title="Car scene recognition",
                         examples=["crv.jpg",
                                   "cadillac1.jpeg",
                                   "cadillacinterior.jpeg",
                                   "outsidescene.jpg",
                                   "wheel.jpeg",
                                   "crv_inside.jpg",
                                  "chevy_exterior.jpeg",
                                  "lexus_inside.jpeg",
                                  "malibu_interior.jpeg",
                                  "maserati_interior.jpeg",
                                  "highlander_inside.jpeg",
                                  "altima_inside.jpeg",
                                  "altima_outside.jpeg"],
                         description=description ) 

interface.launch()