Spaces:
Sleeping
Sleeping
Commit
Β·
f95dd5b
1
Parent(s):
7dc8b07
Initial commit with YOLOv5 Sunspot Hunter app
Browse files- README.md +13 -1
- app.py +47 -0
- best.pt +3 -0
- example1.jpg +0 -0
- requirements.txt +6 -0
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
---
|
2 |
title: Yolov5 Sunspot Hunter
|
3 |
-
emoji:
|
4 |
colorFrom: green
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
@@ -10,4 +10,16 @@ pinned: false
|
|
10 |
license: ecl-2.0
|
11 |
---
|
12 |
|
|
|
|
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
title: Yolov5 Sunspot Hunter
|
3 |
+
emoji: π
|
4 |
colorFrom: green
|
5 |
colorTo: blue
|
6 |
sdk: gradio
|
|
|
10 |
license: ecl-2.0
|
11 |
---
|
12 |
|
13 |
+
# YOLOv5 Sunspot Hunter
|
14 |
+
|
15 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
16 |
+
|
17 |
+
## Desenvolvedor
|
18 |
+
|
19 |
+
Desenvolvido por Ramon Mayor Martins (2023)
|
20 |
+
|
21 |
+
- Email: [rmayormartins@gmail.com](mailto:rmayormartins@gmail.com)
|
22 |
+
- Homepage: [https://rmayormartins.github.io/](https://rmayormartins.github.io/)
|
23 |
+
- Twitter: [@rmayormartins](https://twitter.com/rmayormartins)
|
24 |
+
- GitHub: [https://github.com/rmayormartins](https://github.com/rmayormartins)
|
25 |
+
|
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
|
7 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
|
8 |
+
|
9 |
+
|
10 |
+
def detect(img):
|
11 |
+
|
12 |
+
img_arr = np.array(img)
|
13 |
+
|
14 |
+
results = model(img_arr)
|
15 |
+
|
16 |
+
|
17 |
+
fig, ax = plt.subplots()
|
18 |
+
ax.imshow(img_arr)
|
19 |
+
|
20 |
+
|
21 |
+
for *xyxy, conf, cls in results.xyxy[0].cpu().numpy():
|
22 |
+
x1, y1, x2, y2 = map(int, xyxy)
|
23 |
+
label = model.names[int(cls)]
|
24 |
+
ax.add_patch(plt.Rectangle((x1, y1), x2-x1, y2-y1, fill=False, color='red', linewidth=2))
|
25 |
+
ax.text(x1, y1, f'{label} {conf:.2f}', color='white', fontsize=8, bbox={'facecolor': 'red', 'alpha': 0.5})
|
26 |
+
|
27 |
+
plt.axis('off')
|
28 |
+
|
29 |
+
|
30 |
+
fig.canvas.draw()
|
31 |
+
pil_img = Image.fromarray(np.array(fig.canvas.renderer._renderer))
|
32 |
+
plt.close(fig)
|
33 |
+
|
34 |
+
return pil_img
|
35 |
+
|
36 |
+
#Gradio
|
37 |
+
iface = gr.Interface(
|
38 |
+
fn=detect,
|
39 |
+
inputs=gr.Image(type="pil"),
|
40 |
+
outputs=gr.Image(type="pil"),
|
41 |
+
title="YOLOv5 Sun Spot Hunter",
|
42 |
+
description="Object detector (solar spot/sunspot hunter) trained using YOLOv5 and labeled in Makesense.ai",
|
43 |
+
examples=[["example1.jpg"]]
|
44 |
+
)
|
45 |
+
|
46 |
+
|
47 |
+
iface.launch(debug=True)
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:40be2dbf0abbfb9465a1c4712e4d4d1c552e45bdbc4f309ce617760352605739
|
3 |
+
size 14443816
|
example1.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
torch
|
3 |
+
numpy
|
4 |
+
Pillow
|
5 |
+
matplotlib
|
6 |
+
|