Installing torchvision inside docker image

Environment :
-jetson tx2
- jetback 4.2
- cuda 10.0

i am trying to build docker image that use pytorch and torchvision on jetson ,i can not use https://ngc.nvidia.com/catalog/containers/nvidia:l4t-pytorch image because it requires jetback 4.4 so i decided to build it from scratch . i installed pytorch successfully but i failed to install torchvision here is the
dockerfile i used .

FROM nvcr.io/nvidia/l4t-base:r32.3.1
ENV DEBIAN_FRONTEND noninteractive

RUN wget https://nvidia.box.com/shared/static/phqe92v26cbhqjohwtvxorrwnmrnfx1o.whl -O torch-1.3.0-cp36-cp36m-linux_aarch64.whl

RUN apt-get update && apt-get install -y
python3-opencv ca-certificates python3-dev git wget sudo python-setuptools &&
rm -rf /var/lib/apt/lists/*

RUN wget https://bootstrap.pypa.io/get-pip.py &&
python3 get-pip.py &&
rm get-pip.py
RUN apt-get update -y && apt-get install -y pkg-config
zlib1g-dev libwebp-dev
libtbb2 libtbb-dev
libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
cmake
RUN apt-get install -y
autoconf
autotools-dev
build-essential
gcc
RUN pip install --upgrade pip

RUN pip3 install cython
RUN pip3 install numpy torch-1.3.0-cp36-cp36m-linux_aarch64.whl
RUN pip3 install scapy
RUN pip3 install numpy
RUN pip3 install --upgrade numpy

RUN apt-get install -y libjpeg-dev zlib1g-dev
RUN apt-get install -y git
RUN git clone --branch v0.4.0 https://github.com/pytorch/vision torchvision
RUN cd torchvision && export BUILD_VERSION=0.4.0 && python3 setup.py install && pip3 install -y ‘pillow<7’

but i got this error

Traceback (most recent call last):
File “setup.py”, line 13, in
import torch
File “/usr/local/lib/python3.6/dist-packages/torch/init.py”, line 81, in
from torch._C import *
ImportError: libnvToolsExt.so.1: cannot open shared object file: No such file or directory
The command ‘/bin/sh -c cd torchvision && export BUILD_VERSION=0.4.0 && python3 setup.py install && pip3 install -y ‘pillow<7’’ returned a non-zero code: 1

Hi @khaledm.gamal95, did you set your Docker daemon’s default-runtime to nvidia?

https://github.com/dusty-nv/jetson-containers#docker-default-runtime

This is needed so that the CUDA libraries are available during build-time for the container.

This is for JetPack 4.4 . i am running jetPack 4.2 so i have NVIDIA Container Runtime on Jetson

You would need to run the same step regardless of JetPack version. It is to enable the NVIDIA Container Runtime during docker build operations.

Thanks a lot for your help. I solved this problem by adding this

RUN pip3 install torchvision==0.2.2

instead of

RUN apt-get install -y git
RUN git clone --branch v0.4.0 https://github.com/pytorch/vision torchvision
RUN cd torchvision && export BUILD_VERSION=0.4.0 && python3 setup.py install && pip3 install -y 'pillow<7

I can not access usb camera inside docker container i tried to use --device /dev/video0 in docker run command but that does not work

i was trying to access usb cam in docker container to use it with opencv in function cv2.VideoCapture() so the solution is to use --device /dev/video0 in docker run command and in cv2.VideoCapture(‘dev/video0’) instead of cv2.VideoCapture(0) because i got this error when i used 0 instead of ‘dev/video0’

assert cap.isOpened(), 'Cannot capture source'
    AssertionError: Cannot capture source
1 Like