-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
955c233
commit 0876098
Showing
6 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |