Skip to content

Commit 0a4d5d1

Browse files
authored
Merge pull request #149 from intel/update-branch
Vision edge ai (#398)
2 parents 75b0a03 + 3db8972 commit 0a4d5d1

31 files changed

+2069
-1190
lines changed
Lines changed: 182 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,123 @@
11
# Copyright (C) 2024 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
FROM ubuntu:24.10
5-
4+
FROM ubuntu:24.04
65
ARG DEBIAN_FRONTEND=noninteractive
7-
USER root
8-
9-
#--------------------------------------------------------------------------------------------------------------------------
10-
# Essential Tools
11-
#--------------------------------------------------------------------------------------------------------------------------
126

7+
#=======================================
8+
# Core System Setup
9+
#=======================================
1310
RUN apt update -y && apt install -y \
14-
software-properties-common \
15-
build-essential \
16-
wget \
17-
gpg \
18-
curl \
19-
pciutils \
20-
git \
21-
cmake \
22-
libopencv-dev \
23-
v4l-utils \
24-
libusb-1.0-0-dev \
25-
libssl-dev \
26-
libgtk-3-dev \
27-
pkg-config \
28-
udev \
29-
libudev-dev \
30-
libglfw3-dev \
31-
libgl1-mesa-dev \
32-
libglu1-mesa-dev \
33-
python3-pip \
34-
python3-dev \
35-
python3-setuptools \
36-
python3-opencv
37-
38-
#--------------------------------------------------------------------------------------------------------------------------
39-
# Graphic & NPU drivers and tools
40-
#--------------------------------------------------------------------------------------------------------------------------
41-
42-
# Install Intel GPU Drivers
11+
software-properties-common build-essential wget gpg pciutils git cmake \
12+
libglib2.0-0 libtbb12 v4l-utils libusb-1.0-0-dev libssl-dev libgtk-3-dev pkg-config \
13+
udev libudev-dev libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev libva-dev yasm libx264-dev libx265-dev \
14+
sudo
15+
16+
#=======================================
17+
# Install Python 3.9
18+
#=======================================
19+
RUN add-apt-repository ppa:deadsnakes/ppa && apt update -y && \
20+
apt install -y python3.9 python3.9-distutils python3.9-dev && \
21+
rm -rf /var/lib/apt/lists/*
22+
23+
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
24+
RUN ln -sf /usr/bin/python3 /usr/bin/python
25+
26+
RUN wget https://bootstrap.pypa.io/get-pip.py && \
27+
python3.9 get-pip.py && \
28+
rm get-pip.py
29+
30+
# Install system-wide python3-numpy for OpenCV build
31+
RUN apt update -y && apt install -y python3-numpy
32+
33+
# Install pip dependencies, ensuring NumPy is compatible with Python 3.9
34+
RUN python3.9 -m pip install --upgrade pip setuptools wheel
35+
#=======================================
36+
# Intel GPU Drivers
37+
#=======================================
4338
RUN wget -qO - https://repositories.intel.com/gpu/intel-graphics.key | \
44-
gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg && \
45-
echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] \
46-
https://repositories.intel.com/gpu/ubuntu noble client" \
47-
> /etc/apt/sources.list.d/intel-gpu-noble.list && \
48-
apt update -y && apt install -y libze1 intel-level-zero-gpu intel-opencl-icd clinfo
39+
gpg --yes --dearmor -o /usr/share/keyrings/intel-graphics.gpg && \
40+
echo "deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/gpu/ubuntu noble unified" > \
41+
/etc/apt/sources.list.d/intel-gpu-noble.list && \
42+
apt update && apt install -y \
43+
libze-intel-gpu1 libze1 intel-opencl-icd clinfo intel-gsc \
44+
&& rm -rf /var/lib/apt/lists/*
45+
46+
#=======================================
47+
# Intel NPU Drivers
48+
#=======================================
49+
RUN wget -qP /tmp \
50+
https://github.com/intel/linux-npu-driver/releases/download/v1.13.0/intel-driver-compiler-npu_1.13.0.20250131-13074932693_ubuntu24.04_amd64.deb \
51+
https://github.com/intel/linux-npu-driver/releases/download/v1.13.0/intel-fw-npu_1.13.0.20250131-13074932693_ubuntu24.04_amd64.deb \
52+
https://github.com/intel/linux-npu-driver/releases/download/v1.13.0/intel-level-zero-npu_1.13.0.20250131-13074932693_ubuntu24.04_amd64.deb && \
53+
dpkg -i /tmp/*.deb && rm -f /tmp/*.deb
54+
55+
#=======================================
56+
# Intel Performance Tools
57+
#=======================================
58+
RUN git clone --recursive https://github.com/intel/pcm /tmp/pcm && \
59+
cmake -S /tmp/pcm -B /tmp/pcm/build && \
60+
cmake --build /tmp/pcm/build --parallel && \
61+
make -C /tmp/pcm/build install && rm -rf /tmp/pcm
62+
63+
#=======================================
64+
# Compile FFmpeg with VAAPI Support
65+
#=======================================
66+
WORKDIR /tmp
67+
RUN wget -q https://ffmpeg.org/releases/ffmpeg-7.0.2.tar.bz2 && \
68+
tar -xjf ffmpeg-7.0.2.tar.bz2 && \
69+
mv ffmpeg-7.0.2 ffmpeg
70+
71+
WORKDIR /tmp/ffmpeg
72+
RUN ./configure \
73+
--prefix=/usr/local \
74+
--enable-gpl \
75+
--enable-libx264 \
76+
--enable-libx265 \
77+
--enable-vaapi \
78+
--enable-shared \
79+
&& make -j$(nproc) && \
80+
make install && \
81+
ldconfig && \
82+
rm -rf /tmp/ffmpeg /tmp/ffmpeg-7.0.2.tar.bz2
4983

50-
# Install Intel NPU Drivers
84+
#=======================================
85+
# OpenCV Compilation
86+
#=======================================
5187
WORKDIR /tmp
52-
RUN apt install -y libtbb12
53-
RUN wget https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-driver-compiler-npu_1.10.0.20241107-11729849322_ubuntu24.04_amd64.deb \
54-
https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-fw-npu_1.10.0.20241107-11729849322_ubuntu24.04_amd64.deb \
55-
https://github.com/intel/linux-npu-driver/releases/download/v1.10.0/intel-level-zero-npu_1.10.0.20241107-11729849322_ubuntu24.04_amd64.deb && \
56-
dpkg -i *.deb && rm -f *.deb
57-
58-
# Install Intel PCM Tool
59-
RUN git clone --recursive https://github.com/intel/pcm && \
60-
cd pcm && mkdir build && cd build && \
61-
cmake .. && cmake --build . --parallel && make install && \
62-
rm -rf /tmp/pcm
63-
64-
#--------------------------------------------------------------------------------------------------------------------------
65-
# OpenVINO
66-
#--------------------------------------------------------------------------------------------------------------------------
67-
68-
WORKDIR /opt/intel
69-
# Install OpenVINO
70-
RUN curl -L https://storage.openvinotoolkit.org/repositories/openvino/packages/2024.5/linux/l_openvino_toolkit_ubuntu24_2024.5.0.17288.7975fa5da0c_x86_64.tgz \
71-
--output openvino.tgz
72-
RUN tar -xf openvino.tgz
73-
RUN mv l_openvino_toolkit_ubuntu24_2024.5.0.17288.7975fa5da0c_x86_64 openvino
74-
RUN cd openvino && sed -i 's/24\.04/24\.10/g' ./install_dependencies/install_openvino_dependencies.sh && \
75-
bash ./install_dependencies/install_openvino_dependencies.sh -y
76-
ENV OPENVINO_DIR=/opt/intel/openvino
77-
RUN pip install --pre -U openvino openvino-dev --extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly --break-system-packages
78-
79-
#--------------------------------------------------------------------------------------------------------------------------
80-
# librealsense
81-
#--------------------------------------------------------------------------------------------------------------------------
88+
RUN git clone https://github.com/opencv/opencv.git
89+
RUN git clone https://github.com/opencv/opencv_contrib.git
90+
91+
WORKDIR /tmp/opencv/build
92+
RUN cmake -D CMAKE_BUILD_TYPE=Release \
93+
-D CMAKE_INSTALL_PREFIX=/usr/local \
94+
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
95+
-D WITH_VAAPI=ON \
96+
-D WITH_FFMPEG=ON \
97+
-D WITH_V4L=ON \
98+
-D FFMPEG_LIBRARY_DIR=/usr/local/lib \
99+
-D FFMPEG_INCLUDE_DIR=/usr/local/include \
100+
-D PYTHON_EXECUTABLE=$(which python3) \
101+
-D BUILD_TESTS=OFF \
102+
-D BUILD_PERF_TESTS=OFF \
103+
-D BUILD_EXAMPLES=OFF \
104+
-D INSTALL_PYTHON_EXAMPLES=OFF \
105+
-D INSTALL_C_EXAMPLES=OFF \
106+
-D WITH_CUDA=OFF \
107+
-D WITH_GTK=OFF \
108+
-D WITH_QT=OFF \
109+
-D WITH_GSTREAMER=OFF \
110+
-D WITH_DNN=OFF \
111+
-D WITH_GAPI=OFF \
112+
.. && \
113+
make -j$(nproc) && \
114+
make install && \
115+
ldconfig && \
116+
rm -rf /tmp/opencv /tmp/opencv*
82117

118+
#=======================================
119+
# RealSense SDK
120+
#=======================================
83121
WORKDIR /tmp
84122
RUN git clone https://github.com/IntelRealSense/librealsense
85123

@@ -89,59 +127,87 @@ RUN cd librealsense && mkdir build && cd build && \
89127
make install && \
90128
ldconfig
91129

92-
#python3 -m pip install --no-cache-dir pyrealsense2 --break-system-packages
93-
94-
ENV PYTHONPATH=/usr/local/lib/python3.12/dist-packages
95-
96-
#--------------------------------------------------------------------------------------------------------------------------
97-
# Required Python Packages
98-
#--------------------------------------------------------------------------------------------------------------------------
99-
100-
RUN pip3 install --break-system-packages \
101-
fire \
102-
distro \
103-
zeroconf \
104-
psutil \
105-
cython \
106-
prometheus-client \
107-
zeroconf
130+
RUN apt install -y sudo
131+
RUN cd /tmp/librealsense && ./scripts/setup_udev_rules.sh
108132

109-
RUN pip3 install --break-system-packages \
110-
yt-dlp \
111-
youtube_dl \
112-
pafy
133+
RUN python3.9 -m pip install pyrealsense2
113134

135+
#=======================================
136+
# Python Environment
137+
#=======================================
114138
RUN apt remove -y python3-blinker || true
115-
RUN pip3 install --break-system-packages \
116-
flask \
117-
flask_bootstrap
118-
119-
RUN pip3 install --break-system-packages \
120-
nncf \
121-
ultralytics
122-
123-
#--------------------------------------------------------------------------------------------------------------------------
124-
# Video Steams Download
125-
#--------------------------------------------------------------------------------------------------------------------------
126139

140+
RUN python3.9 -m pip install \
141+
fire distro zeroconf psutil cython prometheus-client \
142+
yt-dlp youtube_dl pafy flask flask_bootstrap nncf ultralytics
143+
144+
RUN python3.9 -m pip install --pre -U openvino openvino-dev[onnx] \
145+
--extra-index-url https://storage.openvinotoolkit.org/simple/wheels/nightly
146+
147+
#=======================================
148+
# Web Assets
149+
#=======================================
150+
WORKDIR /workspace/static
151+
RUN mkdir -p js css && \
152+
wget -O js/jquery.min.js https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js && \
153+
wget -O js/moment.min.js https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js && \
154+
wget -O js/bootstrap-datetimepicker.min.js https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js && \
155+
wget -O js/turf.min.js https://unpkg.com/@turf/[email protected]/dist/turf.min.js && \
156+
wget -O js/jqxcore.js https://jqwidgets.com/public/jqwidgets/jqxcore.js && \
157+
wget -O js/jqxdraw.js https://jqwidgets.com/public/jqwidgets/jqxdraw.js && \
158+
wget -O js/jqxgauge.js https://jqwidgets.com/public/jqwidgets/jqxgauge.js && \
159+
wget -O css/bootstrap.min.css https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css && \
160+
wget -O css/bootstrap-datetimepicker.min.css https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker.min.css && \
161+
wget -O css/chart.min.css https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.css
162+
163+
#=======================================
164+
# Video Streams
165+
#=======================================
127166
WORKDIR /opt/videos
128-
129-
RUN wget -O streat.mp4 https://videos.pexels.com/video-files/3759216/3759216-sd_640_360_30fps.mp4
130-
#RUN wget -O animals.mp4 https://videos.pexels.com/video-files/4938060/4938060-uhd_2732_1440_30fps.mp4
131-
132-
#--------------------------------------------------------------------------------------------------------------------------
133-
# Models Preparation
134-
#--------------------------------------------------------------------------------------------------------------------------
135-
167+
RUN wget -O tmp.mp4 https://videos.pexels.com/video-files/17476835/17476835-hd_1920_1080_30fps.mp4 && \
168+
ffmpeg -i tmp.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" -c:a copy video_1.mp4 && \
169+
wget -O tmp.mp4 https://videos.pexels.com/video-files/4997787/4997787-hd_1920_1080_24fps.mp4 && \
170+
ffmpeg -i tmp.mp4 -vf "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" -c:a copy video_2.mp4 && \
171+
rm -f tmp.mp4
172+
173+
#=======================================
174+
# Numpy for python 3.9
175+
#=======================================
176+
RUN apt remove -y python3-numpy
177+
RUN python3.9 -m pip install "numpy>=2.0.0"
178+
179+
#=======================================
180+
# Model Installation & Build
181+
#=======================================
182+
ENV PATH=/home/intel/.local/bin:${PATH}
183+
COPY --chown=intel:intel ./utils/models.sh /tmp/
136184
WORKDIR /opt/models
185+
RUN bash /tmp/models.sh
186+
WORKDIR /workspace/utils
137187

138-
COPY ./utils/models.sh /tmp/
139-
RUN /tmp/models.sh
140-
188+
#=======================================
189+
# Application Setup
190+
#=======================================
191+
WORKDIR /workspace
141192

193+
COPY --chown=intel:intel ./app.py /workspace/
194+
COPY --chown=intel:intel ./static /workspace/static/
195+
COPY --chown=intel:intel ./templates /workspace/templates/
196+
COPY --chown=intel:intel ./utils/*.py* /workspace/utils/
142197

143-
RUN rm -rf /tmp/*
198+
WORKDIR /workspace/utils
199+
RUN python3 setup.py build_ext --quiet --inplace
144200

145-
WORKDIR /workspace
201+
#=======================================
202+
# Create default user 'intel'
203+
#=======================================
204+
RUN useradd -m -s /bin/bash intel && chown -R intel:intel /home/intel
205+
RUN echo "intel ALL=(root) NOPASSWD: /usr/local/sbin/pcm" >> /etc/sudoers
206+
RUN groupadd -f render
207+
RUN groupadd -f video
208+
RUN usermod -a -G video intel
209+
RUN usermod -a -G render intel
146210

211+
#USER intel
147212

213+
WORKDIR /workspace

usecases/ai/vision-edge-ai/Makefile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ DOCKER_COMPOSE_ENV = \
3030
MKL_THREADING_LAYER=gnu \
3131
CURRENT_DIR=$(CURRENT_DIR) \
3232
PORT=${PORT} \
33-
HOST_ADDRESS=$(HOST_ADDRESS)
33+
HOST_ADDRESS=$(HOST_ADDRESS) \
34+
CUSTOM_LOGO_IMAGE=$(CUSTOM_LOGO_IMAGE)
3435

3536
#----------------------------------------------------------------------------------------------------------------------
3637
# Targets
@@ -39,29 +40,47 @@ default: run
3940

4041
.PHONY: build app run bash
4142

42-
build:
43+
build:
4344
@$(call msg, Building Docker image ${DOCKER_IMAGE_NAME} ...)
44-
@$(DOCKER_COMPOSE_ENV) docker-compose build
45-
@docker-compose run --rm $(SERVICE_NAME) bash -c \
46-
'cd ./utils/ && python3 setup.py build_ext --quiet --inplace'
47-
45+
@$(DOCKER_COMPOSE_ENV) docker compose build
46+
4847
run: stop
4948
@$(call msg, Running the Vision Edge AI application ...)
50-
@docker-compose up -d
49+
@docker compose up
5150

5251
stop: build
5352
@$(call msg, Stopping the Vision Edge AI application ...)
54-
@docker-compose down --remove-orphans # Ensure old orphaned containers are removed
53+
@docker compose down
5554

5655
install_prerequisites:
5756
@$(call msg, Installing Prerequisites ...)
5857
@cd ./tools && bash ./install.sh
5958

60-
61-
bash:
59+
bash: build
6260
@$(call msg, Opening a bash session in the container ...)
6361
@docker-compose run --rm $(SERVICE_NAME) bash
6462

63+
64+
enable_auto_start: build
65+
@$(call msg, Configuring Vision Edge AI to start automatically on system boot ...)
66+
@if [ ! -f $(CURRENT_DIR)/utils/vision_edge_ai.service ]; then \
67+
echo "Error: utils/vision_edge_ai.service file not found"; \
68+
exit 1; \
69+
fi
70+
71+
@sed 's|{{CURRENT_DIR}}|$(CURRENT_DIR)|g; s|{{DOCKER_IMAGE_NAME}}|$(DOCKER_IMAGE_NAME)|g; s|{{PORT}}|$(PORT)|g; s|{{HOST_ADDRESS}}|$(HOST_ADDRESS)|g' \
72+
$(CURRENT_DIR)/utils/vision_edge_ai.service | sudo tee /etc/systemd/system/vision_edge_ai.service > /dev/null
73+
74+
@sudo systemctl daemon-reload
75+
@sudo systemctl enable vision_edge_ai.service
76+
@echo "Auto-start enabled. Use 'sudo systemctl start vision_edge_ai' to start now,"
77+
@echo "or reboot the system to verify automatic startup."
78+
79+
disable_auto_start: build
80+
@$(call msg, Disabling auto start ...)
81+
@sudo systemctl stop vision_edge_ai.service
82+
@sudo systemctl disable vision_edge_ai.service
83+
6584
#----------------------------------------------------------------------------------------------------------------------
6685
# Helper Functions
6786
#----------------------------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)