Skip to content

Commit

Permalink
Merge pull request #76 from aaide/pull_request/docker
Browse files Browse the repository at this point in the history
Pull Request for Dockerfile Including TextBoxes++ and CRNN pre installed
  • Loading branch information
MhLiao committed Aug 13, 2018
2 parents f3c7dee + 9eed834 commit 212ab68
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 20 deletions.
176 changes: 176 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
FROM nvidia/cuda:7.5-cudnn5-devel-ubuntu14.04
LABEL version="0.1.0"
LABEL version_convention="Semantic Versioning (see www.semver.org)"
LABEL title="Dockerfile for TextBoxes++ with CRNN"
LABEL description="This Dockerfile sets up TextBoxes++\
and CRNN with all their respective dependencies.\
Make sure to run with nvidia-docker"

RUN apt-get update && apt-get install -y --no-install-recommends \
autoconf \
autoconf-archive \
automake \
binutils-dev \
bison \
build-essential \
cmake \
curl \
flex \
g++ \
git \
libatlas-base-dev \
libboost-all-dev \
libdouble-conversion-dev \
libedit-dev \
libevent-dev \
libgeos-dev \
libgflags-dev \
libgoogle-glog-dev \
libhdf5-serial-dev \
libjemalloc-dev \
libkrb5-dev \
libleveldb-dev \
liblmdb-dev \
liblz4-dev \
liblzma-dev \
libmatio-dev \
libnuma-dev \
libopencv-dev \
libprotobuf-dev \
libpython3-dev \
libpython-dev \
libsasl2-dev \
libsnappy-dev \
libssl-dev \
libtool \
pkg-config \
protobuf-compiler \
python-dev \
python-numpy \
python-opencv \
python-pip \
python-scipy \
wget \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/*

ENV CAFFE_ROOT=/opt/caffe
WORKDIR $CAFFE_ROOT


########################################
#### Install CRNN Dependencies #########
########################################

# Install pytorch
WORKDIR /root
RUN git clone https://github.com/torch/distro.git /root/torch --recursive
RUN cd /root/torch && \
bash install-deps;
RUN cd /root/torch && \
./install.sh

# Update the PATHs
# This is normally done by calling
# source ~/torch/install/bin/torch-activate
ENV LUA_PATH='/root/.luarocks/share/lua/5.1/?.lua;/root/.luarocks/share/lua/5.1/?/init.lua;/root/torch/install/share/lua/5.1/?.lua;/root/torch/install/share/lua/5.1/?/init.lua;./?.lua;/root/torch/install/share/luajit-2.1.0-beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua'
ENV LUA_CPATH='/root/.luarocks/lib/lua/5.1/?.so;/root/torch/install/lib/lua/5.1/?.so;./?.so;/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so'
ENV PATH=/root/torch/install/bin:$PATH
ENV LD_LIBRARY_PATH=/root/torch/install/lib:$LD_LIBRARY_PATH
ENV DYLD_LIBRARY_PATH=/root/torch/install/lib:$DYLD_LIBRARY_PATH
ENV LUA_CPATH='/root/torch/install/lib/?.so;'$LUA_CPATH

# Install Folly
RUN git clone -b v0.35.0 --depth 1 https://github.com/facebook/folly
RUN cd /root/folly/folly && \
autoreconf -ivf && \
./configure && \
make && \
make install && \
ldconfig

# Install fbthrift
RUN git clone -b v0.24.0 --depth 1 https://github.com/facebook/fbthrift
COPY patches/fbthrift.diff ${CAFFE_ROOT}/patches/fbthrift.diff
RUN cd /root/fbthrift && \
git apply ${CAFFE_ROOT}/patches/fbthrift.diff
RUN cd /root/fbthrift/thrift && \
autoreconf -ivf && \
./configure && \
make && \
make install

# Install thpp
RUN git clone -b v1.0 https://github.com/facebook/thpp
COPY patches/thpp.diff ${CAFFE_ROOT}/patches/thpp.diff
RUN cd /root/thpp && \
git apply ${CAFFE_ROOT}/patches/thpp.diff
RUN cd /root/thpp/thpp && \
./build.sh

# Install fblualib
RUN git clone -b v1.0 https://github.com/facebook/fblualib
RUN cd /root/fblualib/fblualib && \
./build.sh

########################################
#### Install CRNN ######################
########################################
COPY crnn/src ${CAFFE_ROOT}/crnn/src

# Install CRNN
RUN cd ${CAFFE_ROOT}/crnn/src && \
./build_cpp.sh

########################################
#### Install Textboxes++ Dependencies ##
########################################
WORKDIR $CAFFE_ROOT

# Cython needs to be installed seperately
Copy python ${CAFFE_ROOT}/python
RUN pip install Cython==0.28.5
RUN pip install -r python/requirements.txt

########################################
#### Install Textboxes++ ###############
########################################
WORKDIR $CAFFE_ROOT
# Include Build context
COPY caffe.cloc ${CAFFE_ROOT}/caffe.cloc
Copy cmake ${CAFFE_ROOT}/cmake
Copy CMakeLists.txt ${CAFFE_ROOT}/CMakeLists.txt
Copy include ${CAFFE_ROOT}/include
Copy matlab ${CAFFE_ROOT}/matlab
Copy src ${CAFFE_ROOT}/src
COPY tools ${CAFFE_ROOT}/tools
COPY LICENSE ${CAFFE_ROOT}/LICENSE
COPY scripts ${CAFFE_ROOT}/scripts

# CUDA_ARCH_NAME=Manual is a workaround the lack of compute_60 or higher in cuda7.5's cuda
# Required for recent GPUs
RUN mkdir build && \
cd build && \
cmake .. -DCUDA_ARCH_NAME=Manual && \
make -j"$(nproc)"

# HACK: OpenCV can be confused by (the lack of) this driver in some systems
RUN ln /dev/null /dev/raw1394

ENV PYCAFFE_ROOT $CAFFE_ROOT/python
ENV PYTHONPATH $PYCAFFE_ROOT:$PYTHONPATH
ENV PATH $CAFFE_ROOT/build/tools:$PYCAFFE_ROOT:$PATH
RUN echo "$CAFFE_ROOT/build/lib" >> /etc/ld.so.conf.d/caffe.conf && ldconfig


########################################
#### COPY Context required at runtime ##
########################################
COPY crnn/data ${CAFFE_ROOT}/crnn/data
COPY data ${CAFFE_ROOT}/data
COPY demo_images ${CAFFE_ROOT}/demo_images
COPY examples ${CAFFE_ROOT}/examples
COPY README.md ${CAFFE_ROOT}/README.md


WORKDIR /opt/caffe
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ Please cite the related works in your publications if it helps your research:
}

### Contents

1. [Requirements](#requirements)
2. [Installation](#installation)
3. [Models](#models)
4. [Demo](#demo)
5. [Train](#train)
3. [Docker](#docker)
4. [Models](#models)
5. [Demo](#demo)
6. [Train](#train)


### Requirements

Expand All @@ -64,6 +67,7 @@ Please cite the related works in your publications if it helps your research:

Please refer to [Caffe Installation](http://caffe.berkeleyvision.org/install_apt.html) to ensure other dependencies;


### Installation

1. compile TextBoxes++ (This is a modified version of caffe so you do not need to install the official caffe)
Expand All @@ -79,8 +83,34 @@ Please refer to [Caffe Installation](http://caffe.berkeleyvision.org/install_apt
cd crnn/src/
sh build_cpp.sh
```

### Docker

Build Docke Image

docker build -t tbpp_crnn:gpu .

This can take +1h, so go get a coffee ;)

Once this is done you can start a container via `nvidia-docker`.

nvidia-docker run -it --rm tbpp_crnn:gpu bash

To check if the GPU is available inside the docker container you can run `nvidia-smi`.

It's recommendable to mount the `./models` and `./crnn/model/` directories to include the downloaded [models](#models).

nvidia-docker run -it \
--rm \
-v ${PWD}/models:/opt/caffe/models \
-v ${PWD}/crrn/model:/opt/caffe/crrn/model \
tbpp_crnn:gpu bash

For convenince this command is executed when running `./run.bash`.


### Models

1. pre-trained model on SynthText (used for training):
[Dropbox](https://www.dropbox.com/s/kpv17f3syio95vn/model_pre_train_syn.caffemodel?dl=0);
[BaiduYun](https://pan.baidu.com/s/1htV2j4K)
Expand All @@ -99,7 +129,9 @@ Please refer to [Caffe Installation](http://caffe.berkeleyvision.org/install_apt

Please place the crnn model in "./crnn/model/"


### Demo

Download the ICDAR 2015 model and place it in "./models/"
```Shell
python examples/text/demo.py
Expand Down
29 changes: 29 additions & 0 deletions patches/fbthrift.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/thrift/compiler/generate/t_rb_generator.cc b/thrift/compiler/generate/t_rb_generator.cc
index aa0bfbc..6efe46a 100644
--- a/thrift/compiler/generate/t_rb_generator.cc
+++ b/thrift/compiler/generate/t_rb_generator.cc
@@ -312,7 +312,10 @@ void t_rb_generator::generate_enum(t_enum* tenum) {
//Populate the hash
int32_t value = (*c_iter)->get_value();

- first ? first = false : f_types_ << ", ";
+ if (first)
+ first = false;
+ else
+ f_types_ << ", ";
f_types_ << value << " => \"" << capitalize((*c_iter)->get_name()) << "\"";

}
@@ -323,7 +326,10 @@ void t_rb_generator::generate_enum(t_enum* tenum) {
first = true;
for (c_iter = constants.begin(); c_iter != constants.end(); ++c_iter) {
// Populate the set
- first ? first = false: f_types_ << ", ";
+ if (first)
+ first = false;
+ else
+ f_types_ << ", ";
f_types_ << capitalize((*c_iter)->get_name());
}
f_types_ << "]).freeze" << endl;

69 changes: 69 additions & 0 deletions patches/thpp.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
diff --git a/thpp/CMakeLists.txt b/thpp/CMakeLists.txt
index 62159fb..000801b 100644
--- a/thpp/CMakeLists.txt
+++ b/thpp/CMakeLists.txt
@@ -33,9 +33,10 @@ INCLUDE_DIRECTORIES(

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

-ADD_SUBDIRECTORY("gtest-1.7.0")
+
+ADD_SUBDIRECTORY("googletest-release-1.7.0")
INCLUDE_DIRECTORIES(
- "${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0/include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.7.0/include"
)

SET(src
diff --git a/thpp/build.sh b/thpp/build.sh
index 838560c..05292d1 100755
--- a/thpp/build.sh
+++ b/thpp/build.sh
@@ -15,14 +15,14 @@ if [[ ! -r ./Tensor.h ]]; then
exit 1
fi

-rm -rf gtest-1.7.0 gtest-1.7.0.zip
-curl -JLO https://googletest.googlecode.com/files/gtest-1.7.0.zip
-if [[ $(sha1sum -b gtest-1.7.0.zip | cut -d' ' -f1) != \
- 'f85f6d2481e2c6c4a18539e391aa4ea8ab0394af' ]]; then
- echo "Invalid gtest-1.7.0.zip file" >&2
+rm -rf googletest-release-1.7.0.zip
+curl -JLO https://github.com/google/googletest/archive/release-1.7.0.zip
+if [[ $(sha1sum -b googletest-release-1.7.0.zip | cut -d' ' -f1) != \
+ 'f89bc9f55477df2fde082481e2d709bfafdb057b' ]]; then
+ echo "Invalid googletest-release-1.7.0.zip file" >&2
exit 1
fi
-unzip gtest-1.7.0.zip
+unzip googletest-release-1.7.0.zip

# Build in a separate directory
mkdir -p build
diff --git a/thpp/detail/TensorGeneric.h b/thpp/detail/TensorGeneric.h
index 144d23d..a7ebb10 100644
--- a/thpp/detail/TensorGeneric.h
+++ b/thpp/detail/TensorGeneric.h
@@ -188,17 +188,17 @@ template <> struct TensorOps<real> {
}
static void _max(THTensor* values, THLongTensor* indices,
THTensor* t, int dim) {
- return THTensor_(max)(values, indices, t, dim);
+ return THTensor_(max)(values, indices, t, dim, 1);
}
static void _min(THTensor* values, THLongTensor* indices,
THTensor* t, int dim) {
- return THTensor_(min)(values, indices, t, dim);
+ return THTensor_(min)(values, indices, t, dim, 1);
}
static void _sum(THTensor* r, THTensor* t, int dim) {
- return THTensor_(sum)(r, t, dim);
+ return THTensor_(sum)(r, t, dim, 1);
}
static void _prod(THTensor* r, THTensor* t, int dim) {
- return THTensor_(prod)(r, t, dim);
+ return THTensor_(prod)(r, t, dim, 1);
}
static void _cumsum(THTensor* r, THTensor* t, int dim) {
return THTensor_(cumsum)(r, t, dim);

34 changes: 17 additions & 17 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
Cython==0.19.2
numpy==1.7.1
scipy==0.13.2
scikit-image==0.9.3
matplotlib==1.3.1
ipython==3.0.0
h5py==2.2.0
leveldb==0.191
networkx==1.8.1
nose==1.3.0
pandas==0.12.0
python-dateutil>=1.4,<2
protobuf==2.5.0
python-gflags==2.0
pyyaml==3.10
Pillow==2.3.0
six==1.1.0
Cython==0.28.5
h5py==2.8.0
ipython==5.8.0
leveldb==0.194
matplotlib==2.2.2
networkx==2.1
nose==1.3.7
numpy==1.8.2
pandas==0.23.4
Pillow==5.2.0
protobuf==3.6.0
pydot==1.2.4
python-dateutil==2.7.3
python-gflags==3.1.2
pyyaml==3.10
scikit-image==0.9.3
scipy==0.13.3
shapely==1.6.4
six==1.11.0
12 changes: 12 additions & 0 deletions run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Start docker container
#
# Usage:
# sudo ./runRos.sh

nvidia-docker run -it \
--rm \
-v ${PWD}/models:/opt/caffe/models \
-v ${PWD}/crnn/model:/opt/caffe/crnn/model \
tbpp_crnn:gpu bash

0 comments on commit 212ab68

Please sign in to comment.