nakamura196 commited on
Commit
76f623a
1 Parent(s): 61646cc

feat: initial commit

Browse files
Files changed (6) hide show
  1. .gitignore +4 -0
  2. app.py +72 -0
  3. best.pt +3 -0
  4. requirements.txt +6 -0
  5. test/00000017.jpg +0 -0
  6. test/00000020.jpg +0 -0
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .venv
2
+ __pycache__
3
+ .DS_Store
4
+ yolov8n.pt
app.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 = "東京大学史料編纂所所蔵『日本一鑑』の行検出モデル"
8
+ description = """東京大学史料編纂所所蔵『日本一鑑』の行検出モデルは、YOLOv8をベースにしたモデルです。このモデルは、東京大学史料編纂所所蔵『日本一鑑』の行を検出するために訓練されています。モデルは、画像を入力として受け取り、画像内の東京大学史料編纂所所蔵『日本一鑑』の行を検出し、その位置を示すバウンディングボックスを描画します。モデルは、信頼度スコアとIOUスコアの2つのしきい値を受け取ります。信頼度スコアは、検出されたオブジェクトの信頼度を示し、IOUスコアは、検出されたオブジェクトの位置の正確さを示します。"""
9
+
10
+ image_path= [
11
+ ['test/00000017.jpg', 0.1, 0.1],
12
+ ['test/00000020.jpg', 0.1, 0.1]
13
+ ]
14
+
15
+ # Load YOLO model
16
+ model = YOLO('best.pt')
17
+
18
+ def yolov8_img_inference(
19
+ image: gr.Image = None,
20
+ conf_threshold: gr.Slider = 0.25,
21
+ iou_threshold: gr.Slider = 0.45,
22
+ ):
23
+ """
24
+ YOLOv8 inference function
25
+ Args:
26
+ image: Input image
27
+ conf_threshold: Confidence threshold
28
+ iou_threshold: IOU threshold
29
+ Returns:
30
+ Rendered image
31
+ """
32
+ results = model.predict(image, conf=conf_threshold, iou=iou_threshold)
33
+ render = render_result(model=model, image=image, result=results[0])
34
+
35
+ json_data = json.loads(results[0].tojson())
36
+
37
+ return render, json_data
38
+
39
+
40
+ inputs_image = [
41
+ gr.Image(type="filepath", label="Input Image"),
42
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.25, step=0.05, label="Confidence Threshold"),
43
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"),
44
+ ]
45
+
46
+ outputs_image =[
47
+ gr.Image(type="filepath", label="Output Image"),
48
+ gr.JSON(label="Output JSON")
49
+ ]
50
+ interface_image = gr.Interface(
51
+ fn=yolov8_img_inference,
52
+ inputs=inputs_image,
53
+ outputs=outputs_image,
54
+ title=model_heading,
55
+ description=description,
56
+ examples=image_path,
57
+ cache_examples=False,
58
+ theme='huggingface'
59
+ )
60
+
61
+
62
+ '''
63
+ demo = gr.TabbedInterface(
64
+ [interface_image],
65
+ tab_names=['Image inference']
66
+ ).queue() # .launch()
67
+ '''
68
+
69
+ demo = interface_image
70
+
71
+ # if __name__ == "__main__":
72
+ demo.launch()
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:052e427e42c8b05ea43223479bc970d8743e70eea21d2140f9cf03014cf511f7
3
+ size 52040385
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch
2
+ ultralytics
3
+ ultralyticsplus
4
+ opencv_python
5
+ requests
6
+ gradio
test/00000017.jpg ADDED
test/00000020.jpg ADDED