Skip to content

Commit 151d264

Browse files
committed
added docker container to run the object detection api
1 parent dc11af5 commit 151d264

File tree

3 files changed

+70
-2
lines changed

3 files changed

+70
-2
lines changed

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ If your installation works correctly you should see the following output:
104104

105105
![Tensorflow Object Detection API Tutorial Output](doc/tutorial_output.png)
106106

107+
### Run the Tensorflow Object Detection API with Docker
108+
109+
Installing the Tensorflow Object Detection API can be hard because there are lots of errors that can occur depending on your operating system. Docker makes it easy to setup the Tensorflow Object Detection API because you only need to download the files inside the [docker folder](docker/) and run **docker-compose up**.
110+
111+
After running the command docker should automatically download and install everything needed for the Tensorflow Object Detection API and open Jupyter on port 8888. If you also want to have access to the bash for training models you can simply say **docker exec -it CONTAINER_ID**. For more information check out [Dockers documentation](https://docs.docker.com/).
112+
113+
If you experience any problems with the docker files be sure to let me know.
114+
107115
### 2. Gathering data
108116

109117
Now that the Tensorflow Object Detection API is ready to go, we need to gather the images needed for training.
@@ -346,8 +354,6 @@ bazel run --config=opt tensorflow/lite/toco:toco -- \
346354

347355
If you are using a floating point model like a faster rcnn you'll need to change to command a bit:
348356

349-
bazel run --config=opt tensorflow/lite/toco:toco -- --input_file=$OUTPUT_DIR/tflite_graph.pb --output_file=$OUTPUT_DIR/detect.tflite --input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor --output_arrays=TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3 --inference_type=FLOAT --allow_custom_ops
350-
351357
```bash
352358
export OUTPUT_DIR=/tmp/tflite
353359
bazel run --config=opt tensorflow/lite/toco:toco -- \

docker/Dockerfile

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FROM nvidia/cuda:10.1-cudnn7-devel
2+
3+
RUN apt-get update && apt-get upgrade -y
4+
5+
RUN apt-get install -y git
6+
7+
RUN apt-get install -y python3 && apt-get install -y python3-pip
8+
9+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
10+
11+
# Installing the Tensorflow Object Detection API (https://gilberttanner.com/blog/installing-the-tensorflow-object-detection-api)
12+
RUN git clone --depth 1 https://github.com/tensorflow/models.git
13+
14+
# Install object detection api dependencies
15+
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y protobuf-compiler python3-pil python3-lxml python3-tk && \
16+
pip3 install Cython && \
17+
pip3 install contextlib2 && \
18+
pip3 install jupyter && \
19+
pip3 install matplotlib && \
20+
pip3 install tensorflow==1.14.0
21+
22+
# Install pycocoapi
23+
RUN git clone --depth 1 https://github.com/cocodataset/cocoapi.git && \
24+
cd cocoapi/PythonAPI && \
25+
make -j8 && \
26+
cp -r pycocotools /models/research && \
27+
cd ../../ && \
28+
rm -rf cocoapi
29+
30+
# Get protoc 3.0.0, rather than the old version already in the container
31+
RUN apt-get install -y curl unzip
32+
33+
RUN curl -OL "https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip" && \
34+
unzip protoc-3.0.0-linux-x86_64.zip -d proto3 && \
35+
mv proto3/bin/* /usr/local/bin && \
36+
mv proto3/include/* /usr/local/include && \
37+
rm -rf proto3 protoc-3.0.0-linux-x86_64.zip
38+
39+
# Run protoc on the object detection repo
40+
RUN cd models/research && \
41+
protoc object_detection/protos/*.proto --python_out=.
42+
43+
# Set the PYTHONPATH to finish installing the API
44+
ENV PYTHONPATH=$PYTHONPATH:/models/research/slim
45+
ENV PYTHONPATH=$PYTHONPATH:/models/research
46+
47+
# Entrypoint
48+
WORKDIR /models/research/object_detection
49+
ENTRYPOINT ["jupyter", "notebook", "--ip=0.0.0.0", "--no-browser", "--allow-root"]

docker/docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '2.3'
2+
3+
services:
4+
tensorflow_object_detection_api:
5+
container_name: tensorflow_object_detection_api
6+
build: ./
7+
restart: always
8+
ports:
9+
- '8888:8888'
10+
runtime: nvidia
11+
environment:
12+
- DISPLAY=$DISPLAY
13+
- NVIDIA_VISIBLE_DEVICES=all

0 commit comments

Comments
 (0)