Skip to content

Instantly share code, notes, and snippets.

@schelleg
Created December 2, 2019 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schelleg/40fb06238709ece43c52cfc770860e20 to your computer and use it in GitHub Desktop.
Save schelleg/40fb06238709ece43c52cfc770860e20 to your computer and use it in GitHub Desktop.
A (No-Cross) Compile of PyTorch and OpenCV using AWS A1 instances

This gist is a collection of bash scripts and a Jupyter noteookbooks to support the blog entitled:

"A (No-Cross) Compile of PyTorch and OpenCV using AWS A1 instances"

#!/bin/bash
# References
# https://docs.opencv.org/master/d2/de6/tutorial_py_setup_in_ubuntu.html
set -x
set -e
if [ "$1" == "a1" ]; then
threads=16
elif [ "$1" == "u96" ]; then
threads=4
elif [ "$1" == "install" ]; then
make install
ldconfig
else
echo '$0 <a1|u96|install>'
exit 0
fi
# if needed
# sudo apt-get update
# sudo apt-get -y install build-essential cmake zip python3-opencv python3-dev python3-numpy
opencv_version=3.4.3
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
mkdir opencv-${opencv_version}/build
cd opencv-${opencv_version}/build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_WITH_DEBUG_INFO=OFF \
-D BUILD_DOCS=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS=ON \
-D BUILD_opencv_ts=OFF \
-D BUILD_PERF_TESTS=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D ENABLE_NEON=ON \
-D WITH_LIBV4L=ON \
-D WITH_GSTREAMER=ON \
-D BUILD_opencv_dnn=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${opencv_version}/modules \
../
make -j$threads
cd ../..
#!/bin/bash
# Following a nice blog here:
# https://medium.com/hardware-interfacing/how-to-install-pytorch-v4-0-on-raspberry-pi-3b-odroids-and-other-arm-based-devices-91d62f2933c7
set -x
set -e
if [ "$1" == "a1" ]; then
threads=16
sudo apt-get update
sudo apt-get -y install build-essential libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools python3-pip
pip3 install wheel
elif [ "$1" == "u96" ]; then
threads=4
sudo apt-get update
sudo apt-get install libopenblas-dev
else
echo "$0 <a1|u96>"
exit 0
fi
mkdir pytorch_install && cd pytorch_install
git clone --recursive https://github.com/pytorch/pytorch
cd pytorch
export NO_CUDA=1
export NO_DISTRIBUTED=1
export NO_MKLDNN=1
export NO_NNPACK=1
export NO_QNNPACK=1
export MAX_JOBS=$threads
python3 setup.py bdist_wheel
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment