nakamura196 commited on
Commit
4aed34b
1 Parent(s): d3859cc

feat: initial commit

Browse files
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ .DS_Store
2
+ # yolo*.pt
3
+ # __pycache__
4
+ gradio_queue.db
5
+ __pycache__
6
+ .venv
U+4F4E_200004148_00022_1_X1018_Y0469.jpg ADDED
U+5F3E_200015779_00112_1_X0978_Y2642.jpg ADDED
U+7CBE_100249537_00088_1_X1463_Y0823.jpg ADDED
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ from ultralytics import YOLO
4
+
5
+ # Model Heading and Description
6
+ model_heading = "YOLOv11x くずし字認識サービス(一文字)"
7
+ description = """YOLOv11x くずし字認識サービス(一文字) Gradio demo for classification. Upload an image or click an example image to use."""
8
+
9
+ article = "<p style='text-align: center'>YOLOv11x くずし字認識サービス(一文字) is a classification model trained on the <a href=\"http://codh.rois.ac.jp/char-shape/\">日本古典籍くずし字データセット</a>.</p>"
10
+
11
+ image_path= [
12
+
13
+ ['U+4F4E_200004148_00022_1_X1018_Y0469.jpg'],
14
+ ['U+5F3E_200015779_00112_1_X0978_Y2642.jpg'],
15
+ ['U+7CBE_100249537_00088_1_X1463_Y0823.jpg']
16
+ ]
17
+
18
+ # Load YOLO model
19
+ model = YOLO('yolo11x-cls.pt')
20
+
21
+ def YOLOv11x_img_inference(
22
+ image: gr.Image = None,
23
+ ):
24
+ """
25
+ YOLOv11x inference function
26
+ Args:
27
+ image: Input image
28
+ Returns:
29
+ top5_json: JSON format of top 5 class names and confidence
30
+ """
31
+ results = model.predict(image)
32
+ result = results[0]
33
+ class_names = result.names # クラスIDとクラス名のマッピング
34
+
35
+ # 上位5件のクラスIDと信頼度を取得して、nameとconfのペアでリストに変換
36
+ top5_list = [
37
+ {
38
+ "name": chr(int(class_names[class_id][2:], 16)), # Unicodeコードポイントを文字に変換
39
+ "conf": float(conf)
40
+ }
41
+ for class_id, conf in zip(result.probs.top5, result.probs.top5conf)
42
+ ]
43
+
44
+ # JSON形式に変換
45
+ top5_json = json.dumps(top5_list, ensure_ascii=False, indent=2)
46
+
47
+ return top5_json
48
+
49
+
50
+ inputs_image = [
51
+ gr.Image(type="filepath", label="Input Image"),
52
+ ]
53
+
54
+ outputs_image =[
55
+ gr.JSON(label="Output JSON")
56
+ ]
57
+ demo = gr.Interface(
58
+ fn=YOLOv11x_img_inference,
59
+ inputs=inputs_image,
60
+ outputs=outputs_image,
61
+ title=model_heading,
62
+ description=description,
63
+ examples=image_path,
64
+ article=article,
65
+ cache_examples=False
66
+ # allow_flagging=False
67
+ )
68
+
69
+ demo.launch(share=False)
requirements-dev.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # --upgrade pip
2
+ -r requirements.txt
3
+ gradio
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ultralytics
yolo11x-cls.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d99eb486b696d14286e431d189b84ff2468ddb6f721facb4a865011a0e897352
3
+ size 68169393