Coder Social home page Coder Social logo

turdusmerula / docker-opencv-gpu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fizmath/docker-opencv-gpu

0.0 1.0 0.0 35.61 MB

GPU-accelerated Docker container with OpenCV 4.5, Python 3.8 , GStreamer and CUDA 10,2

Python 60.34% Dockerfile 39.66%

docker-opencv-gpu's Introduction

Docker Build Status Docker DockerHub Pulls

GPU-accelerated Docker container with OpenCV 4.5, Python 3.8 and GStreamer

  • opencv + opencv_contrib
  • Python 3.8.0
  • Ubuntu 18.04 LTS
  • GStreamer 1.14.5
  • FFMPEG
  • CUDA 10.2
  • NVIDIA GPU arch: 30 35 37 50 52 60 61 70 75
  • CUDA_ARCH_PTX = 75 ( The container does not work with NVIDIA Ampere GPUs sm_86 . For RTX 30 series, please see this new repo)
  • cuDNN: 7.6.5
  • OpenCL
  • Qt5::OpenGL 5.9.5
  • Intel IPP and TBB
  • UNCOMPRESSED SIZE 6.02 GB

Pull the image from here :

How to run :

  • With GPU

    You need to install NVIDIA Container Toolkit on your machine. Run the container by this command :

    $ docker run --gpus all -it --rm  fizmath/gpu-opencv:latest
    root@22067ad0cc87:/myapp#  
    
  • With CPU :

    If no GPU available on your machine, yet you can use the container with Docker

    $ docker run -it --rm fizmath/gpu-opencv:latest
    root@cc00562d816e:/myapp# 
    

    for running the example .py files in this repo with CPU you should comment these two lines :

    net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
    net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)
    

Test with the examples in this repo :

  1. Download this repo . The pretrained models are included, but you just need to download one of them yolov4.weights. And also no arg-parsing for the simplicity

  2. Unzip and set its directory in your machine as your docker volume :

     $ docker run --gpus all -it --rm -v  <your volume dir>:/myapp fizmath/gpu-opencv:latest
     root@771c5bcb2895:/myapp# ls
     Dockerfile  YOLOv4_cam.py  face_SSD.py     model_SSD   model_YOLOv4
     README.md   cv2_info.py    golden_axe.png  model_SURE  super_resolution.py
  3. Print out OpenCV build info into a textfile, check out the produced output in your volume :

    root@771c5bcb2895:/myapp# python3 cv2_info.py
  4. Image Super-Resolution with OpenCV, Cuda and Docker : the included image, a SR image SURE_golden_axe.png will be produced in your volume by the following command :

root@771c5bcb2895:/myapp# python3 super_resolution.py 

compare both images visually. If you run out of GPU memory , make inference by your CPU cores ; see the .py file.

For the next two examples, you need to include these commands to docker run :

  • -e DISPLAY=$DISPLAY : this sends the display id from your machine to the container.

  • --device="/dev/video0:/dev/video0" : this lets the container find the camera.

  • -v /tmp/.X11-unix:/tmp/.X11-unix:rw : this lets the container find the display via X server. In order to display the GUI with Docker, the X client in the Docker container needs to communicate with the host X server.

Note that I tested the above commands in UBUNTU. These may differ in other systems.

  1. Real-time face detection with OpenCV DNN, GStreamer, CUDA and Docker : . Before running the container type in your CMD :

    $ xhost +
    access control disabled, clients can connect from any host

    which allows the user to access the running X server. After being done with the examples type xhost - for the sake of security

     $ docker run --gpus all --rm -it -e DISPLAY=$DISPLAY -v  <volume dir>:/myapp -v /tmp/.X11-unix:/tmp/.X11-unix:rw --device="/dev/video0:/dev/video0"  fizmath/gpu-opencv:latest
     root@1be1f7efabf9:/myapp# python3 face_SSD.py

    img

    I drew encircling ellipses instead of the common face bounding boxes . Click q to terminate the session.

  2. Real-time object detection with YOLO v4, GStreamer, CUDA and Docker. First download yolov4.weights and put it in it's folder. Following from the above:

    root@1be1f7efabf9:/myapp# python3 YOLOv4_cam.py 

    bring some objects from this list in front of your camera.

Inspect the GStreamer API out of the OpenCV wrapper

Type into the container's shell :

root@1be1f7efabf9:/myapp# gst-launch-1.0 videotestsrc ! videoconvert ! autovideosink

then a GStreamer hello world window pops up . See the documentation.

OpenCV and GStreamer debugging

Export OpenCV Log Levels or GStreamer Debug Levels into our container's shell . For example:

root@1be1f7efabf9:/myapp# export OPENCV_LOG_LEVEL=INFO 

or

root@1be1f7efabf9:/myapp# export GST_DEBUG=2

then run one of the examples and browse the output.

Build your own image

The Dockerfile culprit for the image may not have a perfect structure . It is just my own assembly. You may modify, upgrade and build a proper one for your requirements :

$ docker build -f Dockerfile -t <name>:<tag> .

It won't be that straight-forward, you will get some deprecation warnings and compatibility issues.
To keep the image light-weight and compatible with old GPU architectures SM_30 , SM_35 , SM_37 I implanted 10.2-cudnn7-devel-ubuntu18.04 as base image .

docker-opencv-gpu's People

Contributors

fizmath avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.