Spaces:
Build error
Build error
vchiang001
commited on
Commit
β’
86af013
1
Parent(s):
244b9fe
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copied megadetector section from https://huggingface.co/spaces/hlydecker/MegaDetector_v5
|
2 |
+
|
3 |
+
# %%
|
4 |
+
#all imports
|
5 |
+
import gradio as gr
|
6 |
+
import torch
|
7 |
+
import torchvision
|
8 |
+
import numpy as np
|
9 |
+
from PIL import Image
|
10 |
+
|
11 |
+
# %%
|
12 |
+
# Loads a model from github repo, but you need to have the model
|
13 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', "/home/vic/vic_data/dlclive4mega/models/md_v5b.0.0.pt", force_reload=True)
|
14 |
+
|
15 |
+
# %%
|
16 |
+
|
17 |
+
#not sure if we need to resize... maybe just the origin image and see?
|
18 |
+
""" def yolo(im): #size=640):
|
19 |
+
g = (size / max(im.size)) # gain
|
20 |
+
im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize
|
21 |
+
|
22 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', "/home/vic/vic_data/dlclive4mega/models/md_v5b.0.0.pt", force_reload=True)
|
23 |
+
|
24 |
+
results = model(im) # inference
|
25 |
+
results.render() # updates results.imgs with boxes and labels
|
26 |
+
return Image.fromarray(results.imgs[0]) """
|
27 |
+
|
28 |
+
def yolo(im): #size=640):
|
29 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', "/home/vic/vic_data/dlclive4mega/models/md_v5b.0.0.pt", force_reload=True)
|
30 |
+
results = model(im) # inference
|
31 |
+
results.render() # updates results.imgs with boxes and labels
|
32 |
+
return Image.fromarray(results.imgs[0])
|
33 |
+
|
34 |
+
|
35 |
+
# %%
|
36 |
+
#inputs = [image, chosen_model, size]
|
37 |
+
#this is where you show the image as interface
|
38 |
+
inputs = gr.inputs.Image(type="pil", label="Input Image")
|
39 |
+
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
40 |
+
|
41 |
+
|
42 |
+
# %%
|
43 |
+
title = "MegaDetector with DeepLabCut pose estimation"
|
44 |
+
description = "Detect and identify animals, people and vehicles in camera trap images followed by generating poses for humans and animals"
|
45 |
+
article = "<p style='text-align: center'>Detect and identify animals, people and vehicles in camera trap images followed by generating poses for humans and animals</a></p>"
|
46 |
+
|
47 |
+
# %%
|
48 |
+
#running the actual
|
49 |
+
gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, theme="huggingface").launch(enable_queue=True)
|