Spaces:
Sleeping
Sleeping
nakamura196
commited on
Commit
•
5422773
1
Parent(s):
205b762
feat: initial commit
Browse files- .gitignore +6 -0
- app.py +65 -0
- init.sh +5 -0
- model_- 19 may 2024 15_13.pt +3 -0
- requirements-dev.txt +3 -0
- requirements.txt +1 -0
- /343/200/216/345/271/263/345/256/266/347/211/251/350/252/236/343/200/217(/345/233/275/346/226/207/345/255/246/347/240/224/347/251/266/350/263/207/346/226/231/351/244/250/346/217/220/344/276/233).jpg +0 -0
- /343/200/216/346/272/220/346/260/217/347/211/251/350/252/236/343/200/217(/344/272/254/351/203/275/345/244/247/345/255/246/346/211/200/350/224/265).jpg +0 -0
- /343/200/216/346/272/220/346/260/217/347/211/251/350/252/236/343/200/217(/346/235/261/344/272/254/345/244/247/345/255/246/347/267/217/345/220/210/345/233/263/346/233/270/351/244/250/346/211/200/350/224/265).jpg +0 -0
.gitignore
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
yolo*.pt
|
3 |
+
# __pycache__
|
4 |
+
gradio_queue.db
|
5 |
+
__pycache__
|
6 |
+
.venv
|
app.py
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import json
|
3 |
+
|
4 |
+
from ultralyticsplus import YOLO, render_result
|
5 |
+
|
6 |
+
# Model Heading and Description
|
7 |
+
model_heading = "YOLOv8 NDL-DocL Datasets"
|
8 |
+
description = """YOLOv8 NDL-DocL Datasets Gradio demo for object detection. Upload an image or click an example image to use."""
|
9 |
+
|
10 |
+
article = "<p style='text-align: center'>YOLOv5 NDL-DocL Datasets is an object detection model trained on the <a href=\"https://github.com/ndl-lab/layout-dataset\">NDL-DocL Datasets</a>.</p>"
|
11 |
+
|
12 |
+
image_path= [
|
13 |
+
|
14 |
+
['『源氏物語』(東京大学総合図書館所蔵).jpg', 0.25, 0.45],
|
15 |
+
['『源氏物語』(京都大学所蔵).jpg', 0.25, 0.45],
|
16 |
+
['『平家物語』(国文学研究資料館提供).jpg', 0.25, 0.45]
|
17 |
+
]
|
18 |
+
|
19 |
+
# Load YOLO model
|
20 |
+
model = YOLO('model_- 19 may 2024 15_13.pt')
|
21 |
+
|
22 |
+
def yolov8_img_inference(
|
23 |
+
image: gr.Image = None,
|
24 |
+
conf_threshold: gr.Slider = 0.25,
|
25 |
+
iou_threshold: gr.Slider = 0.45,
|
26 |
+
):
|
27 |
+
"""
|
28 |
+
YOLOv8 inference function
|
29 |
+
Args:
|
30 |
+
image: Input image
|
31 |
+
conf_threshold: Confidence threshold
|
32 |
+
iou_threshold: IOU threshold
|
33 |
+
Returns:
|
34 |
+
Rendered image
|
35 |
+
"""
|
36 |
+
results = model.predict(image, conf=conf_threshold, iou=iou_threshold)
|
37 |
+
render = render_result(model=model, image=image, result=results[0])
|
38 |
+
|
39 |
+
json_data = json.loads(results[0].tojson())
|
40 |
+
|
41 |
+
return render, json_data
|
42 |
+
|
43 |
+
|
44 |
+
inputs_image = [
|
45 |
+
gr.Image(type="filepath", label="Input Image"),
|
46 |
+
gr.Slider(minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold"),
|
47 |
+
gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"),
|
48 |
+
]
|
49 |
+
|
50 |
+
outputs_image =[
|
51 |
+
gr.Image(type="filepath", label="Output Image"),
|
52 |
+
gr.JSON(label="Output JSON")
|
53 |
+
]
|
54 |
+
demo = gr.Interface(
|
55 |
+
fn=yolov8_img_inference,
|
56 |
+
inputs=inputs_image,
|
57 |
+
outputs=outputs_image,
|
58 |
+
title=model_heading,
|
59 |
+
description=description,
|
60 |
+
examples=image_path,
|
61 |
+
article=article,
|
62 |
+
cache_examples=False
|
63 |
+
)
|
64 |
+
|
65 |
+
demo.launch(share=False)
|
init.sh
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
wget https://iiif.dl.itc.u-tokyo.ac.jp/iiif/genji/TIFF/A00_6587/01/01_0004.tif/full/1024,/0/default.jpg -O "『源氏物語』(東京大学総合図書館所蔵).jpg"
|
2 |
+
|
3 |
+
wget https://rmda.kulib.kyoto-u.ac.jp/iiif/RB00007030/01/RB00007030_00003_0.ptif/full/1024,/0/default.jpg -O "『源氏物語』(京都大学所蔵).jpg"
|
4 |
+
|
5 |
+
wget https://kotenseki.nijl.ac.jp/api/iiif/100312034/v4/HRSM/HRSM-00396/HRSM-00396-00012.tif/full/1024,/0/default.jpg -O "『平家物語』(国文学研究資料館提供).jpg"
|
model_- 19 may 2024 15_13.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8acb10e585c68b31142f2f4470606da52ce054ab467368b6bfe22ca547620e12
|
3 |
+
size 136737193
|
requirements-dev.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
# --upgrade pip
|
2 |
+
-r requirements.txt
|
3 |
+
gradio
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
ultralyticsplus
|
/343/200/216/345/271/263/345/256/266/347/211/251/350/252/236/343/200/217(/345/233/275/346/226/207/345/255/246/347/240/224/347/251/266/350/263/207/346/226/231/351/244/250/346/217/220/344/276/233).jpg
ADDED
/343/200/216/346/272/220/346/260/217/347/211/251/350/252/236/343/200/217(/344/272/254/351/203/275/345/244/247/345/255/246/346/211/200/350/224/265).jpg
ADDED
/343/200/216/346/272/220/346/260/217/347/211/251/350/252/236/343/200/217(/346/235/261/344/272/254/345/244/247/345/255/246/347/267/217/345/220/210/345/233/263/346/233/270/351/244/250/346/211/200/350/224/265).jpg
ADDED