Skip to content

Commit bbdee4c

Browse files
ppwwyyxxfacebook-github-bot
authored andcommitted
remove C++ deployment example that runs caffe2 format
Summary: n/a Reviewed By: zhanghang1989 Differential Revision: D32602257 fbshipit-source-id: 44f72c807a8150b2fa50058eb5ad7aad673cd6d9
1 parent f5150de commit bbdee4c

File tree

5 files changed

+17
-169
lines changed

5 files changed

+17
-169
lines changed

docker/deploy.Dockerfile

+1-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ WORKDIR $HOME
1212
# Let torchvision find libtorch
1313
ENV CMAKE_PREFIX_PATH=$HOME/.local/lib/python3.6/site-packages/torch/
1414

15-
RUN sudo apt-get update && sudo apt-get install libgflags-dev libgoogle-glog-dev libopencv-dev --yes
16-
RUN pip install mkl-include
17-
18-
# Install the correct version of protobuf (find it at torch/caffe2/proto/caffe2.pb.h after installing pytorch):
19-
RUN wget https://github.com/protocolbuffers/protobuf/releases/download/v3.13.0/protobuf-cpp-3.13.0.tar.gz && tar xf protobuf-cpp-3.13.0.tar.gz
20-
RUN export CXXFLAGS=-D_GLIBCXX_USE_CXX11_ABI=$(python3 -c 'import torch; print(int(torch.compiled_with_cxx11_abi()))'); \
21-
cd protobuf-3.13.0 && \
22-
./configure --prefix=$HOME/.local && make -j && make install
15+
RUN sudo apt-get update && sudo apt-get install libopencv-dev --yes
2316

2417
# install libtorchvision
2518
RUN git clone --branch v0.11.1 https://github.com/pytorch/vision/

tools/deploy/CMakeLists.txt

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
# Copyright (c) Facebook, Inc. and its affiliates.
22
# See https://pytorch.org/tutorials/advanced/cpp_frontend.html
33
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
4-
project(caffe2_mask_rcnn)
4+
project(torchscript_mask_rcnn)
55

66
find_package(Torch REQUIRED)
7-
find_package(gflags REQUIRED) # needed by caffe2
87
find_package(OpenCV REQUIRED)
98
find_package(TorchVision REQUIRED) # needed by export-method=tracing/scripting
109

11-
add_executable(caffe2_mask_rcnn caffe2_mask_rcnn.cpp)
12-
target_link_libraries(
13-
caffe2_mask_rcnn
14-
"${TORCH_LIBRARIES}" gflags glog protobuf ${OpenCV_LIBS})
15-
set_property(TARGET caffe2_mask_rcnn PROPERTY CXX_STANDARD 14)
16-
17-
1810
add_executable(torchscript_mask_rcnn torchscript_mask_rcnn.cpp)
1911
target_link_libraries(
2012
torchscript_mask_rcnn

tools/deploy/README.md

+13-31
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,21 @@ for some high-level background about deployment.
33

44
This directory contains the following examples:
55

6-
1. An example script `export_model.py` (previously called `caffe2_converter.py`)
6+
1. An example script `export_model.py`
77
that exports a detectron2 model for deployment using different methods and formats.
88

9-
2. A few C++ examples that run inference with Mask R-CNN model in Caffe2/TorchScript format.
9+
2. A C++ example that runs inference with Mask R-CNN model in TorchScript format.
1010

1111
## Build
12-
All C++ examples depend on libtorch and OpenCV. Some require more dependencies:
13-
14-
* Running caffe2-format models requires:
15-
* libtorch built with caffe2 inside
16-
* gflags, glog
17-
* protobuf library that matches the version used by PyTorch (version defined in `include/caffe2/proto/caffe2.pb.h` of your PyTorch installation)
18-
* MKL headers if caffe2 is built with MKL
19-
* Running TorchScript-format models produced by `--export-method=caffe2_tracing` requires no other dependencies.
20-
* Running TorchScript-format models produced by `--export-method=tracing` requires libtorchvision (C++ library of torchvision).
21-
22-
We build all examples with one `CMakeLists.txt` that requires all the above dependencies.
23-
Adjust it if you only need one example.
24-
As a reference,
25-
we provide a [Dockerfile](../../docker/deploy.Dockerfile) that
26-
installs all the above dependencies and builds the C++ examples.
12+
Deployment depends on libtorch and OpenCV. Some require more dependencies:
13+
14+
* Running TorchScript-format models produced by `--export-method=caffe2_tracing` requires libtorch
15+
to be built with caffe2 enabled.
16+
* Running TorchScript-format models produced by `--export-method=tracing/scripting` requires libtorchvision (C++ library of torchvision).
17+
18+
All methods are supported in one C++ file that requires all the above dependencies.
19+
Adjust it and remove code you don't need.
20+
As a reference, we provide a [Dockerfile](../../docker/deploy.Dockerfile) that installs all the above dependencies and builds the C++ example.
2721

2822
## Use
2923

@@ -59,26 +53,14 @@ We show a few example commands to export and execute a Mask R-CNN model in C++.
5953
```
6054

6155

62-
* `export-method=caffe2_tracing, format=caffe2` (caffe2 format will be deprecated):
63-
```
64-
./export_model.py --config-file ../../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
65-
--output ./output --export-method caffe2_tracing --format caffe2 \
66-
MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl \
67-
MODEL.DEVICE cpu
68-
69-
./build/caffe2_mask_rcnn --predict_net=output/model.pb --init_net=output/model_init.pb --input=input.jpg
70-
```
71-
72-
7356
## Notes:
7457

7558
1. Tracing/Caffe2-tracing requires valid weights & sample inputs.
7659
Therefore the above commands require pre-trained models and [COCO dataset](https://detectron2.readthedocs.io/tutorials/builtin_datasets.html).
7760
You can modify the script to obtain sample inputs in other ways instead of from COCO.
7861

79-
2. `--run-eval` is implemented only for certain modes
80-
(caffe2_tracing with caffe2 format, or tracing with torchscript format)
62+
2. `--run-eval` is implemented only for tracing mode
8163
to evaluate the exported model using the dataset in the config.
8264
It's recommended to always verify the accuracy in case the conversion is not successful.
8365
Evaluation can be slow if model is exported to CPU or dataset is too large ("coco_2017_val_100" is a small subset of COCO useful for evaluation).
84-
Caffe2 accuracy may be slightly different (within 0.1 AP) from original model due to numerical precisions between different runtime.
66+
`caffe2_tracing` accuracy may be slightly different (within 0.1 AP) from original model due to numerical precisions between different runtime.

tools/deploy/caffe2_mask_rcnn.cpp

-119
This file was deleted.

tools/deploy/export_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ def get_sample_inputs(args):
177177
"--format",
178178
choices=["caffe2", "onnx", "torchscript"],
179179
help="output format",
180-
default="caffe2",
180+
default="torchscript",
181181
)
182182
parser.add_argument(
183183
"--export-method",
184184
choices=["caffe2_tracing", "tracing", "scripting"],
185185
help="Method to export models",
186-
default="caffe2_tracing",
186+
default="tracing",
187187
)
188188
parser.add_argument("--config-file", default="", metavar="FILE", help="path to config file")
189189
parser.add_argument("--sample-image", default=None, type=str, help="sample image for input")

0 commit comments

Comments
 (0)