Skip to content

Commit

Permalink
Merge pull request #12 from rcland12/jetson_develop
Browse files Browse the repository at this point in the history
Jetson develop
  • Loading branch information
rcland12 authored Dec 17, 2023
2 parents 8c68ba4 + a410fd9 commit 71c09d7
Show file tree
Hide file tree
Showing 26 changed files with 7,365 additions and 513 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*.m3u8
stream-*.ts
tritonserver/
data/
triton2/

### Linux ###
*~
Expand Down
32 changes: 0 additions & 32 deletions Dockerfile.triton

This file was deleted.

59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,65 @@ sudo bash -c "echo '/var/swapfile swap swap defaults 0 0' >> /etc/fstab"
```

# Holly Stream
This application will ingest your computers webcam feed (using ffmpeg), apply an object detection task on the feed with bounding boxes, and send that feed via RTMP to an address of your choice. You have the following options for recording and applying a custom object detection model:
This application will ingest your Jetson's camera feed, apply an object detection task with bounding boxes, and send that feed via RTMP to an address of your choice. You have the option to send the video stream to another local machine, or an external web server.

# Prerequisites
On your Jetson Nano, there are a couple of recommended and required steps before you can harness the GPU.

## Allocate more memory (recommended)
Allocating more swap memory will use storage if your device needs more RAM. You can do so with the following commands:
```bash
sudo fallocate -l 4G /var/swapfile
sudo chmod 600 /var/swapfile
sudo mkswap /var/swapfile
sudo swapon /var/swapfile
sudo bash -c "echo '/var/swapfile swap swap defaults 0 0' >> /etc/fstab"
```

## Allow Docker GPU access (required)
In order to allow Docker access to your Jetson Nano GPU, you will have to add the following lines to the file `/etc/docker/daemon.json`.
```bash
{
"runtimes": {
"nvidia": {
"path": "nvidia-container-runtime",
"runtimeArgs": []
}
},
"default-runtime": "nvidia"
}
```
Once you add the line, restart the docker daemon with `sudo systemctl restart docker`.

## Install Docker Compose (required)
Install this on the Ubuntu system Python environment (not inside a Conda or Virtualenv evironment):
```bash
pip3 install --upgrade pip
pip3 install docker-compose==1.27.4
```

Check if it was installed correctly:
```bash
docker-compose version
```

# Installation
You can use Docker or the native operating system:

## Docker Installation
Pull the Jetson Image:
```bash
docker pull rcland12/detection-stream:jetson-latest
```

## Linux Installation
This install script will install all dependencies needed for this application, including OpenCV, PyTorch, Torchvision, and the Triton Inference Client. You will be prompted to type your password in multiple times, and this script should take roughly two or three hours to complete.
```bash
./install.sh
```

# Deployment
#
1. [Record a webcam feed from a Jetson Nano architecture.](#deploying-on-jetson-nano)
2. [Record a webcam feed from a Linux machine.](#deploying-on-a-linux-machine)

Expand Down
54 changes: 10 additions & 44 deletions Dockerfile.jetson → app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
FROM nvcr.io/nvidia/l4t-base:r32.7.1
FROM nvcr.io/nvidia/l4t-ml:r32.7.1-py3
ARG APPDIR="/root/app"
ARG BUILDDIR="/root/build"

# OpenCV (4.5.1) installation from source
# The default OpenCV version on the Jetson Nano (Jetpack 4.6.1) is 4.1.1
# The default version 4.1.1 causes dependency issues
WORKDIR ${BUILDDIR}
ARG OPENCV_VERSION="4.5.1"

RUN sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf" && \
ldconfig && \
apt-get update && \
Expand All @@ -30,36 +24,6 @@ RUN sh -c "echo '/usr/local/cuda/lib64' >> /etc/ld.so.conf.d/nvidia-tegra.conf"
libopenmpi-dev libomp-dev ffmpeg \
libjpeg-dev zlib1g-dev libpython3-dev libfreetype6-dev

RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
unzip opencv.zip && unzip opencv_contrib.zip && \
mv opencv-${OPENCV_VERSION} opencv && mv opencv_contrib-${OPENCV_VERSION} opencv_contrib && \
rm opencv.zip && rm opencv_contrib.zip && \
mkdir ./opencv/build

WORKDIR ${BUILDDIR}/opencv/build

RUN cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr \
-D OPENCV_EXTRA_MODULES_PATH=${BUILDDIR}/opencv_contrib/modules \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 -D WITH_OPENCL=OFF \
-D WITH_CUDA=ON -D CUDA_ARCH_BIN=5.3 -D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON -D WITH_CUBLAS=ON -D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON -D OPENCV_DNN_CUDA=ON -D ENABLE_NEON=ON \
-D WITH_QT=OFF -D WITH_OPENMP=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D WITH_TBB=ON -D BUILD_TBB=ON \
-D BUILD_TESTS=OFF -D WITH_EIGEN=ON -D WITH_V4L=ON -D WITH_LIBV4L=ON \
-D OPENCV_ENABLE_NONFREE=ON -D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_NEW_PYTHON_SUPPORT=ON \
-D BUILD_opencv_python3=TRUE -D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_EXAMPLES=OFF .. && \
make -j4

RUN make install && \
ldconfig && \
make clean && \
apt-get update && \
cd ../.. && rm -rf opencv opencv_contrib


# PyTorch (1.8.0) and Torchvision (0.9.0) installation via pip wheel
WORKDIR ${BUILDDIR}
Expand All @@ -82,15 +46,17 @@ RUN git clone --branch ${TORCHVISION_BRANCH} https://github.com/pytorch/vision t


# Nvidia Triton Inference Server Client installation
RUN wget https://github.com/triton-inference-server/server/releases/download/v2.16.0/tritonserver2.16.0-jetpack4.6.tgz && \
ARG TRITON_VERSION="2.19.0"
RUN wget https://github.com/triton-inference-server/server/releases/download/v${TRITON_VERSION}/tritonserver${TRITON_VERSION}-jetpack4.6.1.tgz && \
mkdir tritonserver && \
tar -xzf tritonserver2.16.0-jetpack4.6.tgz -C ${BUILDDIR}/tritonserver/
tar -xzf tritonserver${TRITON_VERSION}-jetpack4.6.1.tgz -C ${BUILDDIR}/tritonserver/

RUN pip3 install --upgrade pip && \
pip3 install --upgrade grpcio-tools numpy==1.19.4 future attrdict nanocamera && \
pip3 install --upgrade ${BUILDDIR}/tritonserver/clients/python/tritonclient-2.16.0-py3-none-any.whl[all] && \
rm tritonserver2.16.0-jetpack4.6.tgz
pip3 install --upgrade grpcio-tools numpy==1.19.4 future attrdict nanocamera imutils python-dotenv && \
pip3 install --upgrade ${BUILDDIR}/tritonserver/clients/python/tritonclient-${TRITON_VERSION}-py3-none-any.whl[all] && \
rm tritonserver${TRITON_VERSION}-jetpack4.6.1.tgz

WORKDIR ${APPDIR}
COPY jetson.py utilities.py ./
CMD ["python3", "jetson.py"]
COPY main.py utilities.py ./
COPY images/*.png ./images/
CMD ["python3", "main.py"]
54 changes: 54 additions & 0 deletions app/collect_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import cv2
from nanocamera import Camera



def main(
save_path,
number_to_save=100,
period=5,
camera_index=0,
camera_width=1280,
camera_height=720,
camera_fps=30
):
camera = Camera(
device_id=camera_index,
flip=0,
width=camera_width,
height=camera_height,
fps=camera_fps
)

frame_index = 0
picture_index = 0
take_picture = camera_fps * period

while camera.isReady():
frame = camera.read()

if frame_index % take_picture:
cv2.imwrite(save_path + f"pic_{picture_index}.png", frame)
print(f"Saving image {picture_index}/{number_to_save}")
picture_index += 1

if picture_index == number_to_save:
break

frame_index += 1

print(f"Saved {number_to_save} picture to `{save_path}` successfully.")
return



if __name__ == "__main__":
main(
save_path="../data/images/train/",
number_to_save=100,
period=5,
camera_index=0,
camera_width=1280,
camera_height=720,
camera_fps=30
)
Binary file added app/images/santa_hat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/images/santa_hat_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 71c09d7

Please sign in to comment.