Skip to content

Commit

Permalink
add:yolov8 detect
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyoujiang committed May 15, 2024
1 parent 955c233 commit 0876098
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "jetson-examples"
version = "0.0.7"
version = "0.0.9"
authors = [{ name = "luozhixin", email = "[email protected]" }]
description = "Running Gen AI models and applications on NVIDIA Jetson devices with one-line command"
readme = "README.md"
Expand Down
9 changes: 9 additions & 0 deletions reComputer/scripts/yolov8:detect/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ultralytics/ultralytics:latest-jetson

WORKDIR /usr/src/ultralytics
COPY . /usr/src/ultralytics

RUN pip install --no-cache-dir flask

CMD ["python3", "app.py"]

32 changes: 32 additions & 0 deletions reComputer/scripts/yolov8:detect/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Run YOLOv8 Detect Model on Jetson in One Line

## Introduction

This is a simple demo about how to quickly run the ultralytics YOLOv8 detection model on Jetson device.

## Getting Started

- install **jetson-examples** by pip:
```sh
pip3 install jetson-examples
```
- restart reComputer
```sh
sudo restart
```
- run yolov8 detect model on jetson in one line:
```sh
reComputer run yolov8-counter
```

## FAQs
1. The project has been tested on the Jetson Orin platform, and its execution entails the use of Docker; therefore, it is essential to ensure that all necessary Docker components are fully installed and functional.
2. During program execution, you may encounter an ```ERROR: Could not open requirements file.``` This error message does not impact the normal operation of the program and can be safely ignored.
3. If you want to run `Docker` commands without using `sudo` you can configure it with the following commands:
```sh
sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo systemctl restart docker
sudo chmod a+rw /var/run/docker.sock
```

47 changes: 47 additions & 0 deletions reComputer/scripts/yolov8:detect/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from flask import Flask, render_template, Response
import cv2 as cv
from ultralytics import YOLO
import numpy


class JetsonExampleYoloV8:

def __init__(self):
self.app = Flask(__name__)
self.cap = cv.VideoCapture(0)
assert self.cap.isOpened(), "Error reading video file"

print("prepare yolo model")
self.model = YOLO("/usr/src/ultralytics/yolov8n.pt")
print("done")
self.setup_routes()

def setup_routes(self):
@self.app.route('/')
def index():
return render_template("index.html")

@self.app.route('/video-feed')
def video_feed():
return Response(self.gen_frames(),mimetype='multipart/x-mixed-replace; boundary=frame')

def gen_frames(self):
while True:
ret0, frame= self.cap.read()

if not ret0:break

results = self.model.predict(frame, show=False)
annotated_frame = results[0].plot()

ret1, buffer = cv.imencode('.jpg',annotated_frame)
frame = buffer.tobytes()
yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

def run(self):
self.app.run()


if __name__=='__main__':
yolo = JetsonExampleYoloV8()
yolo.run()
3 changes: 3 additions & 0 deletions reComputer/scripts/yolov8:detect/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sudo docker run -it --rm --network host --ipc=host --runtime=nvidia --device=/dev/video0 youjiang9977/yolov8:detect
27 changes: 27 additions & 0 deletions reComputer/scripts/yolov8:detect/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>ultralytics YOLOv8</title>
<style>
.container{
width: 60%;
margin: 0 auto;
display: flex;
justify-content: center;
align-items: center;
}
.container img {
width: 100%;
height: auto;
}
</style>
</head>

<body>
<div class="container">
<img src="{{url_for('video_feed')}}" alt="YOLOv8 Output">
</div>
</body>

</html>

0 comments on commit 0876098

Please sign in to comment.