Spaces:
Runtime error
Runtime error
Commit
·
e1d803c
1
Parent(s):
1121e06
Update main.py
Browse files
main.py
CHANGED
@@ -2,12 +2,41 @@ import gradio as gr
|
|
2 |
import torch
|
3 |
import requests
|
4 |
from torchvision import transforms
|
|
|
|
|
|
|
5 |
|
6 |
model = torch.hub.load("pytorch/vision:v0.6.0", "resnet18", pretrained=True).eval()
|
7 |
response = requests.get("https://git.io/JJkYN")
|
8 |
labels = response.text.split("\n")
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def predict(inp):
|
12 |
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
13 |
with torch.no_grad():
|
|
|
2 |
import torch
|
3 |
import requests
|
4 |
from torchvision import transforms
|
5 |
+
import cv2
|
6 |
+
from geti_sdk.deployment import Deployment
|
7 |
+
from geti_sdk.utils import show_image_with_annotation_scene
|
8 |
|
9 |
model = torch.hub.load("pytorch/vision:v0.6.0", "resnet18", pretrained=True).eval()
|
10 |
response = requests.get("https://git.io/JJkYN")
|
11 |
labels = response.text.split("\n")
|
12 |
|
13 |
|
14 |
+
# Step 1: Load the deployment
|
15 |
+
deployment = Deployment.from_folder("deployment")
|
16 |
+
deployment.load_inference_models(device="CPU")
|
17 |
+
|
18 |
+
|
19 |
+
def resize_image(image, target_dimension):
|
20 |
+
height, width = image.shape[:2]
|
21 |
+
max_dimension = max(height, width)
|
22 |
+
scale_factor = target_dimension / max_dimension
|
23 |
+
new_width = int(width * scale_factor)
|
24 |
+
new_height = int(height * scale_factor)
|
25 |
+
resized_image = cv2.resize(image, (new_width, new_height))
|
26 |
+
return resized_image
|
27 |
+
|
28 |
+
|
29 |
+
def infer(image=None):
|
30 |
+
if image is None:
|
31 |
+
return [None,'Error: No image provided']
|
32 |
+
|
33 |
+
image = resize_image(image, 1200)
|
34 |
+
prediction = deployment.infer(image)
|
35 |
+
output = show_image_with_annotation_scene(image, prediction, show_results=False)
|
36 |
+
output = cv2.cvtColor(output, cv2.COLOR_RGB2BGR)
|
37 |
+
return [output, prediction.overview]
|
38 |
+
|
39 |
+
|
40 |
def predict(inp):
|
41 |
inp = transforms.ToTensor()(inp).unsqueeze(0)
|
42 |
with torch.no_grad():
|