Spaces:
Sleeping
Sleeping
kevinconka
commited on
Commit
•
48ea831
1
Parent(s):
99ec3f3
use seavision
Browse files- .gitignore +1 -0
- app.py +10 -6
- install_private_repos.py +10 -0
- model_yolov5.py +0 -25
.gitignore
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
flagged*/
|
3 |
gradio_cached_examples/
|
4 |
*ipynb
|
|
|
5 |
|
6 |
# macOS
|
7 |
.DS_Store
|
|
|
2 |
flagged*/
|
3 |
gradio_cached_examples/
|
4 |
*ipynb
|
5 |
+
.gradio/
|
6 |
|
7 |
# macOS
|
8 |
.DS_Store
|
app.py
CHANGED
@@ -6,6 +6,7 @@ Any new model should implement the following functions:
|
|
6 |
"""
|
7 |
import os
|
8 |
import glob
|
|
|
9 |
import gradio as gr
|
10 |
from huggingface_hub import get_token
|
11 |
from utils import (
|
@@ -15,7 +16,8 @@ from utils import (
|
|
15 |
FlaggedCounter,
|
16 |
)
|
17 |
from flagging import HuggingFaceDatasetSaver
|
18 |
-
|
|
|
19 |
|
20 |
|
21 |
TITLE = """
|
@@ -42,11 +44,13 @@ h1 {
|
|
42 |
}
|
43 |
"""
|
44 |
|
45 |
-
model = load_model("
|
46 |
-
|
47 |
-
|
48 |
-
model
|
49 |
-
|
|
|
|
|
50 |
|
51 |
# Flagging
|
52 |
dataset_name = "SEA-AI/crowdsourced-sea-images"
|
|
|
6 |
"""
|
7 |
import os
|
8 |
import glob
|
9 |
+
import spaces
|
10 |
import gradio as gr
|
11 |
from huggingface_hub import get_token
|
12 |
from utils import (
|
|
|
16 |
FlaggedCounter,
|
17 |
)
|
18 |
from flagging import HuggingFaceDatasetSaver
|
19 |
+
import install_private_repos
|
20 |
+
from seavision import load_model, AHOY
|
21 |
|
22 |
|
23 |
TITLE = """
|
|
|
44 |
}
|
45 |
"""
|
46 |
|
47 |
+
model = load_model("ahoy-RGB-b2")
|
48 |
+
|
49 |
+
@spaces.GPU
|
50 |
+
def inference(model: AHOY, image):
|
51 |
+
"""Run inference on image and return annotated image."""
|
52 |
+
results = model(image)
|
53 |
+
return results.draw(image, diameter=4)
|
54 |
|
55 |
# Flagging
|
56 |
dataset_name = "SEA-AI/crowdsourced-sea-images"
|
install_private_repos.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
|
4 |
+
if GITHUB_TOKEN is not None:
|
5 |
+
try:
|
6 |
+
cmd = f"pip3 install git+https://{GITHUB_TOKEN}@github.com/SEA-AI/seavision.git"
|
7 |
+
os.system(cmd)
|
8 |
+
except Exception as e:
|
9 |
+
print(f"Error: {e}")
|
10 |
+
raise e
|
model_yolov5.py
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
import spaces
|
2 |
-
import numpy as np
|
3 |
-
import yolov5
|
4 |
-
from yolov5.utils.plots import Annotator, colors
|
5 |
-
from huggingface_hub import get_token
|
6 |
-
|
7 |
-
|
8 |
-
def load_model(model_path, img_size=640):
|
9 |
-
"""Load model from HuggingFace Hub."""
|
10 |
-
model = yolov5.load(model_path, hf_token=get_token())
|
11 |
-
model.img_size = img_size # add img_size attribute
|
12 |
-
return model
|
13 |
-
|
14 |
-
|
15 |
-
@spaces.GPU
|
16 |
-
def inference(model, image):
|
17 |
-
"""Run inference on image and return annotated image."""
|
18 |
-
results = model(image, size=model.img_size)
|
19 |
-
print(f"{results=}")
|
20 |
-
annotator = Annotator(np.asarray(image))
|
21 |
-
for *box, _, cls in reversed(results.pred[0]):
|
22 |
-
# label = f'{model.names[int(cls)]} {conf:.2f}'
|
23 |
-
# print(f'{cls} {conf:.2f} {box}')
|
24 |
-
annotator.box_label(box, "", color=colors(cls, True))
|
25 |
-
return annotator.im
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|