Javiai commited on
Commit
29af150
1 Parent(s): 90a8732

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +86 -0
README.md ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ datasets:
4
+ - Javiai/failures-3D-print
5
+ language:
6
+ - en
7
+ pipeline_tag: object-detection
8
+ ---
9
+
10
+ #3D Failures detection model based on Yolov5
11
+
12
+
13
+ ## How to use
14
+
15
+ ### Download the model
16
+
17
+ ```python
18
+ from huggingface_hub import hf_hub_download
19
+ import torch
20
+
21
+ repo_id = "Javiai/3dprintfails-yolo5vs"
22
+ filenam = "model_torch.pt"
23
+
24
+ model_path = hf_hub_download(repo_id=repo_id, filename=filename)
25
+ ```
26
+
27
+ ### Combine with the original model
28
+
29
+ ```python
30
+ model = torch.hub.load('Ultralytics/yolov5', 'custom', model_path, verbose = False)
31
+ ```
32
+
33
+ ### Prepare an image
34
+
35
+ #### From the original dataset
36
+ ```python
37
+
38
+ from datasets import load_dataset
39
+
40
+ dataset = load_dataset('Javiai/failures-3D-print')
41
+
42
+ image = dataset["train"][0]["image"]
43
+ ```
44
+
45
+ #### From local
46
+
47
+ ```python
48
+
49
+ from PIL import Image
50
+
51
+ image = Image.load("path/to/image")
52
+
53
+ ```
54
+
55
+ ### Inference and show the detection
56
+
57
+ ```python
58
+
59
+ from PIL import ImageDraw
60
+
61
+ draw = ImageDraw.Draw(image)
62
+
63
+ detections = model(image)
64
+
65
+ categories = [
66
+ {'name': 'error', 'color': (0,0,255)},
67
+ {'name': 'extrusor', 'color': (0,255,0)},
68
+ {'name': 'part', 'color': (255,0,0)},
69
+ {'name': 'spaghetti', 'color': (0,0,255)}
70
+ ]
71
+
72
+ for detection in detections.xyxy[0]:
73
+ x1, y1, x2, y2, p, category_id = detection
74
+ x1, y1, x2, y2, category_id = int(x1), int(y1), int(x2), int(y2), int(category_id)
75
+ draw.rectangle((x1, y1, x2, y2),
76
+ outline=categories[category_id]['color'],
77
+ width=1)
78
+ draw.text((x1, y1), categories[category_id]['name'],
79
+ categories[category_id]['color'])
80
+
81
+ image
82
+
83
+ ```
84
+
85
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/63c9c08a5fdc575773c7549b/3ZSkBvN0o8sSpQjGxdwJx.png)
86
+