59

Machine learning environment setup within 10min

 5 years ago
source link: https://www.tuicool.com/articles/hit/qmUfaie
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
EJNjA3Z.jpg!web

O ne of the main problems of machine learning part is installing software because we need to research algorithm, framework and software library for identifying suitable technology for our application. Hence we need to install more software and library on our machine it will take some time to install. Although while installation some issues will come when we need to fix that also. To overcome this problem we are looking for some technique, which is a docker environment.

Why Docker for machine learning???

Docker will take care of below issues.

3qy6riF.png!web

Issues 1:Most of the Machine learning application is running with third -party library and software. Hence as a developer who needs to install more software, After completing the development, project will be deployed to the production so the developer needs to take notes for which software want to install at production environment.

Issues 2:Machine learning world has more choices to consume third-party software to our application(e.g For Detecting object from webcam you can use Open CV and Open GL software) As a developer, who should identify which will be fast and feasible to our application. So if you install more software in your system then definitely, the machine will be slow or crash.

Issues 3:As a developer have to work on more than one project. One project depends on python 2 and another project depends on python 3 so we can’t install both versions on the same system.

Issues 4: We need to download and install and set an environment variable in our system, But Docker is just one command just copy and past then build it. We can easily switch to other versions.

Use case of machine learning with docker

Here, We are going to see Tensorflow object detection with docker.

ieIVJbE.png!web
Tensorflow with docker

Now the time to choose an option for machine learning environment.

Option 1: If you want to run tensorflow object detection app in your machine, You need to install below dependencies here .

  • Protobuf 3.0.0
  • Python-tk
  • Pillow 1.0
  • lxml
  • tf Slim (which is included in the “tensorflow/models/research/” checkout)
  • Jupyter notebook
  • Matplotlib
  • Tensorflow (>=1.9.0)
  • Cython
  • contextlib2
  • cocoapi

Option 2: Install docker on your machine here .

First, Create docker file in your application path and paste the below command on it.

FROM tensorflow/tensorflow:latest

Run the Docker build command.

Now, the tensorflow environment is ready!!!

If you want to install open CV, Just add this one line on docker file.

RUN apt-get install python-opencv -y

I prefer docker compose is a good one to go. So below is my docker and docker compose file for object detection with docker.

Docker file

FROM tensorflow/tensorflow:latest
RUN apt-get update
RUN apt-get install python-opencv -y
ENV APP_HOME /app
WORKDIR $APP_HOME
ADD . $APP_HOME

Docker-compose.yml

version: “3.3”
services:
 app:
 build: .
 command: “python /app/'YOUR PYTHON FILE'.py” 
 ports:
 — 8888:8888
 volumes:
 — .:/app
 — /tmp/.X11-unix:/tmp/.X11-unix
 — /tmp/.docker.xauth:/tmp/.docker.xauth
 privileged: true
 environment: 
 — DISPLAY=$DISPLAY
 devices:
 — /dev/video0:/dev/video0

NOTE :Here the issue is docker has no GUI so we are using X server here and access our system webcam use this command.

/dev/video0:/dev/video0
iIVzymU.png!web
Object detection

Finally, The Most machine learning project is research work so Docker is the best tool to explore all library, software without time waste or system crash for installation.

$……………….……………… Happy coding………………………………….$


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK