nakamura196 commited on
Commit
d83daa9
1 Parent(s): 43eb482
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +10 -15
  3. requirements.txt +1 -1
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Yolov8 Ndl Layout
3
  emoji: 🐢
4
  colorFrom: indigo
5
  colorTo: red
 
1
  ---
2
+ title: Yolov5 Ndl Layout
3
  emoji: 🐢
4
  colorFrom: indigo
5
  colorTo: red
app.py CHANGED
@@ -1,27 +1,24 @@
1
  import gradio as gr
2
- import torch
3
  from PIL import Image
4
- import numpy as np
5
-
6
- model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt')
7
-
8
  import json
9
 
10
- def yolo(im, size=1024):
11
- g = (size / max(im.size)) # gain
12
- im = im.resize((int(x * g) for x in im.size), Image.LANCZOS) # resize
13
 
14
  results = model(im) # inference
15
- if results.imgs:
16
- writable_img = np.copy(results.imgs[0]) # Create a writable copy of the image data
17
- results.imgs[0] = writable_img
18
- results.render() # updates results.imgs with boxes and labels
19
 
20
  df = results.pandas().xyxy[0].to_json(orient="records")
21
  res = json.loads(df)
22
 
 
 
 
 
 
23
  return [
24
- Image.fromarray(results.imgs[0]),
25
  res
26
  ]
27
 
@@ -36,8 +33,6 @@ title = "YOLOv5 NDL-DocL Datasets"
36
  description = "YOLOv5 NDL-DocL Datasets Gradio demo for object detection. Upload an image or click an example image to use."
37
  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>"
38
 
39
- # <a href=\"aaa\"></a>
40
-
41
  examples = [
42
  ['『源氏物語』(東京大学総合図書館所蔵).jpg'],
43
  ['『源氏物語』(京都大学所蔵).jpg'],
 
1
  import gradio as gr
 
2
  from PIL import Image
3
+ import yolov5
 
 
 
4
  import json
5
 
6
+ model = yolov5.load("nakamura196/yolov5-ndl-layout")
7
+
8
+ def yolo(im):
9
 
10
  results = model(im) # inference
 
 
 
 
11
 
12
  df = results.pandas().xyxy[0].to_json(orient="records")
13
  res = json.loads(df)
14
 
15
+ im_with_boxes = results.render()[0] # results.render() returns a list of images
16
+
17
+ # Convert the numpy array back to an image
18
+ output_image = Image.fromarray(im_with_boxes)
19
+
20
  return [
21
+ output_image,
22
  res
23
  ]
24
 
 
33
  description = "YOLOv5 NDL-DocL Datasets Gradio demo for object detection. Upload an image or click an example image to use."
34
  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>"
35
 
 
 
36
  examples = [
37
  ['『源氏物語』(東京大学総合図書館所蔵).jpg'],
38
  ['『源氏物語』(京都大学所蔵).jpg'],
requirements.txt CHANGED
@@ -1 +1 @@
1
- ultralyticsplus
 
1
+ yolov5