LoginSignup
0
3

More than 5 years have passed since last update.

Dockerにtensorflowを組み込んでDeep Learningしてみる

Posted at

はじめに

機械学習やら色々な新しい事を実践的に試すべく
エロサイトを開発中。あなろぼ
開発実践用にオープンしているので広告は入っておりませんのでお気軽にどうぞ。
色々工夫したアプリケーションの作りになっているのでレスポンスは速いはず。

今回のミッション

dockerにTensorFlowをインストールしてDeep Learningを使う環境を構築する

TensorFlowとは

大規模な数値計算を行うライブラリ。
機械学習や深層学習が実践できるが、それだけでなく汎用的な仕組みを提供。
テンソルというの多次元行列計算のこと。

Windows/MacOS/Linuxと各種OSで動かすことが可能で、Python、Java、Go、C言語とさまざまな言語から利用可能。
機械学習のライブラリとして人気が高く資料も充実。

Dockerのインストール

Windowsの人
https://docs.docker.com/docker-for-windows/install/
Macの人
https://docs.docker.com/docker-for-mac/install/

Docker fileの作成

これを適当なワーキングディレクトリに「Dockerfile」として作成


FROM ubuntu:16.04
MAINTAINER test@test.com

ENV LANG C.UTF-8

# install for Python
RUN set -x && \
    apt-get update && \
    apt-get install -y --no-install-recommends \
        build-essential \
        curl \
        libfreetype6-dev \
        libpng12-dev \
        libzmq3-dev \
        pkg-config \
        python3 \
        python3-dev \
        python3-pip \
        python3-setuptools \
        python3-wheel \
        gcc \
        git \
        rsync \
        software-properties-common \
        libgtk2.0-dev \
        libavcodec-dev \
        libavformat-dev \
        libswscale-dev \
        libopencv-dev \
        libdc1394-22 \
        libdc1394-22-dev \
        libjpeg-dev \
        libpng12-dev \
        libtiff5-dev \
        libjasper-dev \
        libavcodec-dev \
        libavformat-dev \
        libswscale-dev \
        libxine2-dev \
        libgstreamer0.10-dev \
        libgstreamer-plugins-base0.10-dev \
        libv4l-dev \
        libtbb-dev \
        libqt4-dev \
        libfaac-dev \
        libmp3lame-dev \
        libopencore-amrnb-dev \
        libopencore-amrwb-dev \
        libtheora-dev \
        libvorbis-dev \
        libxvidcore-dev \
        x264 \
        v4l-utils \
        unzip \
        nano \
        language-pack-ja \
        fonts-ipafont \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN set -x && \
#   pip3 install --upgrade pip && \
    pip3 --no-cache-dir install \
        requests \
        setuptools \
        Pillow \
        nose \
        h5py \
        ipykernel \
        jupyter \
        matplotlib \
        mlxtend \
        numpy \
        pandas \
        scipy \
        sklearn \
        seaborn \
        opencv-python==3.4.0.12 \
        tensorflow==1.5.0 \
        keras==2.1.4 \
        flask

RUN set -x && \
    mkdir -p /root/.config/matplotlib && \
    echo 'backend : Agg' > /root/.config/matplotlib/matplotlibrc && \
    echo 'font.family : IPAPGothic' >> /root/.config/matplotlib/matplotlibrc


ENV LANG ja_JP.UTF-8
ENV LANGUAGE ja_JP.UTF-8
ENV LC_ALL ja_JP.UTF-8

dockerイメージをビルド

Dockerfileが置いてあるワーキングディレクトリ内で下記コマンドを走らせる。
sample-nameはお好きな名前にどうぞ

docker build -t sample-name .

ビルドしたイメージを実行

docker run -it -p 8888:8888 -v `pwd`:/src sample-name

次回からの起動法とコンテナへの接続方法(Dockerの基本操作)

#コンテナ一覧を取得
docker ps -a #これでDockerの一覧を取得。コンテナIDが重要

#コンテナの起動
docker start CONTAINER-ID #上のコマンドで見えるコンテナIDを入力

#コンテナの停止
docker stop CONTAINER-ID #上のコマンドで見えるコンテナIDを入力

#コンテナの再起動
docker restart CONTAINER-ID #上のコマンドで見えるコンテナIDを入力

#コンテナに接続
docker attach CONTAINER-ID #上のコマンドで見えるコンテナIDを入力

TesorFlowのインストール

#コンテナに接続した状態で
pip install --upgrade tensorflow==1.5.0

これだけ、簡単ですな。

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3