WildlifeDatasets commited on
Commit
4cdead4
·
verified ·
1 Parent(s): 2789996

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +54 -0
README.md CHANGED
@@ -25,3 +25,57 @@ Two sources were used for training:
25
 
26
  ## Usage
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  ## Usage
27
 
28
+ The model can be used as any `ultralytics` model.
29
+
30
+ The model needs to be downloaded. This is sufficient to perform once.
31
+
32
+ ```
33
+ import os
34
+ import requests
35
+ from ultralytics import YOLO
36
+
37
+ def download_detector(
38
+ url="https://huggingface.co/BVRA/TurtleDetector/resolve/main/turtle_detector.pt",
39
+ path_model="models/turtle_detector.pt",
40
+ force=False,
41
+ ):
42
+ if not os.path.exists(path_model) or force:
43
+ os.makedirs(os.path.dirname(path_model), exist_ok=True)
44
+ r = requests.get(url, timeout=60)
45
+ r.raise_for_status()
46
+ with open(path_model, "wb") as f:
47
+ f.write(r.content)
48
+
49
+ path_model = "models/turtle_detector.pt"
50
+ download_detector(path_model=path_model)
51
+ ```
52
+
53
+ Once this is done, load the model.
54
+
55
+ ```
56
+ from ultralytics import YOLO
57
+
58
+ path_model = "models/turtle_detector.pt"
59
+ model = YOLO(path_model)
60
+ ```
61
+
62
+ Finally, download an image (or use yours) and run the prediction.
63
+
64
+ ```
65
+ import requests
66
+ from io import BytesIO
67
+ from PIL import Image
68
+
69
+ def load_image(url):
70
+ r = requests.get(url, timeout=30)
71
+ r.raise_for_status()
72
+ return Image.open(BytesIO(r.content)).convert("RGB")
73
+
74
+ img_url = "https://huggingface.co/BVRA/TurtleDetector/resolve/main/images/321595639_581630651.jpg"
75
+ img = load_image(img_url)
76
+
77
+ result = model.predict(img, verbose=False, save=False, show=False)[0]
78
+ img_annotated = result.plot()[:, :, ::-1]
79
+
80
+ Image.fromarray(img_annotated)
81
+ ```