Andy1621 commited on
Commit
c9409e6
1 Parent(s): 05aedea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -5,7 +5,6 @@ import torch
5
  import torch.nn.functional as F
6
  import torchvision.transforms as T
7
  from uniformer import uniformer_small
8
- from imagenet_class_index import imagenet_classnames
9
 
10
  import gradio as gr
11
 
@@ -22,6 +21,11 @@ model.load_state_dict(state_dict['model'])
22
  model = model.to(device)
23
  model = model.eval()
24
 
 
 
 
 
 
25
  # Create an id to label name mapping
26
  imagenet_id_to_classname = {}
27
  for k, v in imagenet_classnames.items():
@@ -44,7 +48,7 @@ def inference(img):
44
  # The model expects inputs of shape: B x C x T x H x W
45
  image = image[None, :, None, ...]
46
 
47
- prediction = model(image, input_type="image")
48
  prediction = F.softmax(prediction, dim=1)
49
  pred_classes = prediction.topk(k=5).indices
50
 
 
5
  import torch.nn.functional as F
6
  import torchvision.transforms as T
7
  from uniformer import uniformer_small
 
8
 
9
  import gradio as gr
10
 
 
21
  model = model.to(device)
22
  model = model.eval()
23
 
24
+ os.system("wget https://huggingface.co/Andy1621/uniformer/blob/main/imagenet_class_index.json")
25
+
26
+ with open("imagenet_class_index.json", "r") as f:
27
+ imagenet_classnames = json.load(f)
28
+
29
  # Create an id to label name mapping
30
  imagenet_id_to_classname = {}
31
  for k, v in imagenet_classnames.items():
 
48
  # The model expects inputs of shape: B x C x T x H x W
49
  image = image[None, :, None, ...]
50
 
51
+ prediction = model(image)
52
  prediction = F.softmax(prediction, dim=1)
53
  pred_classes = prediction.topk(k=5).indices
54