rmayormartins commited on
Commit
2893c3c
1 Parent(s): 2e28a78

Subindo arquivos

Browse files
Files changed (5) hide show
  1. README.md +46 -5
  2. app.py +45 -0
  3. bestyolo5.pt +3 -0
  4. example1.jpg +0 -0
  5. requirements.txt +8 -0
README.md CHANGED
@@ -1,13 +1,54 @@
1
  ---
2
- title: Yolov5 Farm Cattle
3
- emoji: 🐠
4
- colorFrom: red
5
  colorTo: blue
6
  sdk: gradio
7
- sdk_version: 4.31.4
8
  app_file: app.py
9
  pinned: false
10
  license: ecl-2.0
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: YOLOv5 Cattle Counter
3
+ emoji:
4
+ colorFrom: green
5
  colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 4.12.0
8
  app_file: app.py
9
  pinned: false
10
  license: ecl-2.0
11
  ---
12
 
13
+ # YOLOv5 Cattle Counter
14
+
15
+ This project uses a YOLOv5 model to detect and count cattle in images. The model was trained using custom data and is deployedusing Gradio for an interactive web interface.
16
+
17
+
18
+ ## Developer
19
+
20
+ Developed by Ramon Mayor Martins (2023)
21
+
22
+ - Email: [[email protected]](mailto:[email protected])
23
+ - Homepage: [https://rmayormartins.github.io/](https://rmayormartins.github.io/)
24
+ - Twitter: [@rmayormartins](https://twitter.com/rmayormartins)
25
+ - GitHub: [https://github.com/rmayormartins](https://github.com/rmayormartins)
26
+ - my Radio Callsign (PU4MAY) Brazil
27
+
28
+ ## Model Information
29
+ - **Model:** YOLOv5
30
+ - **Task:** Object Detection
31
+ - **Classes:** Cattle
32
+
33
+ ## How to Use
34
+ 1. Upload an image of cattle.
35
+ 2. The model will detect and count the number of cattle in the image.
36
+ 3. The output will display the image with bounding boxes around detected cattle and the total count.
37
+
38
+ ## Example
39
+ You can use the provided example image to test the model.
40
+
41
+ ## Installation
42
+ To install the necessary dependencies, run:
43
+ ```bash
44
+ pip install -r requirements.txt
45
+
46
+ ## License
47
+
48
+ This project is released under the ECL-2.0 license.
49
+
50
+
51
+ ---
52
+ *Check out the configuration reference at [Hugging Face Spaces Config Reference](https://huggingface.co/docs/hub/spaces-config-reference).*
53
+
54
+
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import torch
5
+ import matplotlib.pyplot as plt
6
+
7
+ # modelo
8
+ model = torch.hub.load('ultralytics/yolov5', 'custom', path='bestyolo5.pt')
9
+
10
+ def detect(img):
11
+ img_arr = np.array(img)
12
+ results = model(img_arr)
13
+
14
+ fig, ax = plt.subplots()
15
+ ax.imshow(img_arr)
16
+
17
+ cattle_count = 0
18
+ for *xyxy, conf, cls in results.xyxy[0].cpu().numpy():
19
+ x1, y1, x2, y2 = map(int, xyxy)
20
+ label = model.names[int(cls)]
21
+ if label == 'cattle':
22
+ cattle_count += 1
23
+ ax.add_patch(plt.Rectangle((x1, y1), x2-x1, y2-y1, fill=False, color='red', linewidth=2))
24
+ ax.text(x1, y1, f'{label} {conf:.2f}', color='white', fontsize=8, bbox={'facecolor': 'red', 'alpha': 0.5})
25
+
26
+ plt.axis('off')
27
+
28
+ fig.canvas.draw()
29
+ pil_img = Image.fromarray(np.array(fig.canvas.renderer._renderer))
30
+ plt.close(fig)
31
+
32
+ return pil_img, cattle_count
33
+
34
+ # gradio
35
+ iface = gr.Interface(
36
+ fn=detect,
37
+ inputs=gr.Image(type="pil"),
38
+ outputs=[gr.Image(type="pil"), gr.Textbox(label="Number of Cattle Detected")],
39
+ title="YOLOv5 Cattle Counter",
40
+ description="Object detector trained to count cattle using YOLOv5.",
41
+ examples=[["example1.jpg"]]
42
+ )
43
+
44
+ if __name__ == "__main__":
45
+ iface.launch()
bestyolo5.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:69283e3a5d8edeb906cdf04cbda320a7a542f191fd28302d4057a54d4ad57f70
3
+ size 14390952
example1.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ gradio==4.29.0
2
+ numpy
3
+ Pillow
4
+ torch
5
+ matplotlib
6
+
7
+
8
+