Spaces:
Runtime error
Runtime error
debug
Browse files
app.py
CHANGED
|
@@ -1,24 +1,21 @@
|
|
| 1 |
import os
|
| 2 |
import json
|
| 3 |
-
from typing import List
|
| 4 |
|
| 5 |
import torch
|
| 6 |
import torch.nn.functional as F
|
| 7 |
import torchvision.transforms as T
|
| 8 |
-
from
|
| 9 |
-
from torchvision.transforms._transforms_video import NormalizeVideo
|
| 10 |
-
from uniformer import uniformer_small, uniformer_base, uniformer_small_plus, uniformer_base_ls
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
|
| 14 |
# Device on which to run the model
|
| 15 |
# Set to cuda to load on GPU
|
| 16 |
device = "cpu"
|
| 17 |
-
os.system("https://huggingface.co/Andy1621/uniformer/blob/main/uniformer_small_in1k.pth")
|
| 18 |
# Pick a pretrained model
|
| 19 |
model = uniformer_small()
|
| 20 |
state_dict = torch.load('uniformer_small_in1k.pth', map_location='cpu')
|
| 21 |
-
model.load_state_dict(state_dict)
|
| 22 |
|
| 23 |
# Set to eval mode and move to desired device
|
| 24 |
model = model.to(device)
|
|
@@ -56,6 +53,7 @@ def inference(img):
|
|
| 56 |
pred_classes = prediction.topk(k=5).indices
|
| 57 |
|
| 58 |
pred_class_names = [imagenet_id_to_classname[str(i.item())] for i in pred_classes[0]]
|
|
|
|
| 59 |
return "Top 5 predicted labels: %s" % ", ".join(pred_class_names)
|
| 60 |
|
| 61 |
inputs = gr.inputs.Image(type='pil')
|
|
|
|
| 1 |
import os
|
| 2 |
import json
|
|
|
|
| 3 |
|
| 4 |
import torch
|
| 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 |
|
| 11 |
# Device on which to run the model
|
| 12 |
# Set to cuda to load on GPU
|
| 13 |
device = "cpu"
|
| 14 |
+
os.system("wget https://huggingface.co/Andy1621/uniformer/blob/main/uniformer_small_in1k.pth")
|
| 15 |
# Pick a pretrained model
|
| 16 |
model = uniformer_small()
|
| 17 |
state_dict = torch.load('uniformer_small_in1k.pth', map_location='cpu')
|
| 18 |
+
model.load_state_dict(state_dict['model'])
|
| 19 |
|
| 20 |
# Set to eval mode and move to desired device
|
| 21 |
model = model.to(device)
|
|
|
|
| 53 |
pred_classes = prediction.topk(k=5).indices
|
| 54 |
|
| 55 |
pred_class_names = [imagenet_id_to_classname[str(i.item())] for i in pred_classes[0]]
|
| 56 |
+
pred_class_probs = []
|
| 57 |
return "Top 5 predicted labels: %s" % ", ".join(pred_class_names)
|
| 58 |
|
| 59 |
inputs = gr.inputs.Image(type='pil')
|