You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.4 KiB

6 years ago
  1. # Installation
  2. ## Dependencies
  3. Tensorflow Object Detection API depends on the following libraries:
  4. * Protobuf 3.0.0
  5. * Python-tk
  6. * Pillow 1.0
  7. * lxml
  8. * tf Slim (which is included in the "tensorflow/models/research/" checkout)
  9. * Jupyter notebook
  10. * Matplotlib
  11. * Tensorflow (>=1.12.0)
  12. * Cython
  13. * contextlib2
  14. * cocoapi
  15. For detailed steps to install Tensorflow, follow the [Tensorflow installation
  16. instructions](https://www.tensorflow.org/install/). A typical user can install
  17. Tensorflow using one of the following commands:
  18. ``` bash
  19. # For CPU
  20. pip install tensorflow
  21. # For GPU
  22. pip install tensorflow-gpu
  23. ```
  24. The remaining libraries can be installed on Ubuntu 16.04 using via apt-get:
  25. ``` bash
  26. sudo apt-get install protobuf-compiler python-pil python-lxml python-tk
  27. pip install --user Cython
  28. pip install --user contextlib2
  29. pip install --user jupyter
  30. pip install --user matplotlib
  31. ```
  32. Alternatively, users can install dependencies using pip:
  33. ``` bash
  34. pip install --user Cython
  35. pip install --user contextlib2
  36. pip install --user pillow
  37. pip install --user lxml
  38. pip install --user jupyter
  39. pip install --user matplotlib
  40. ```
  41. <!-- common_typos_disable -->
  42. **Note**: sometimes "sudo apt-get install protobuf-compiler" will install
  43. Protobuf 3+ versions for you and some users have issues when using 3.5.
  44. If that is your case, try the [manual](#Manual-protobuf-compiler-installation-and-usage) installation.
  45. ## COCO API installation
  46. Download the
  47. [cocoapi](https://github.com/cocodataset/cocoapi) and
  48. copy the pycocotools subfolder to the tensorflow/models/research directory if
  49. you are interested in using COCO evaluation metrics. The default metrics are
  50. based on those used in Pascal VOC evaluation. To use the COCO object detection
  51. metrics add `metrics_set: "coco_detection_metrics"` to the `eval_config` message
  52. in the config file. To use the COCO instance segmentation metrics add
  53. `metrics_set: "coco_mask_metrics"` to the `eval_config` message in the config
  54. file.
  55. ```bash
  56. git clone https://github.com/cocodataset/cocoapi.git
  57. cd cocoapi/PythonAPI
  58. make
  59. cp -r pycocotools <path_to_tensorflow>/models/research/
  60. ```
  61. ## Protobuf Compilation
  62. The Tensorflow Object Detection API uses Protobufs to configure model and
  63. training parameters. Before the framework can be used, the Protobuf libraries
  64. must be compiled. This should be done by running the following command from
  65. the tensorflow/models/research/ directory:
  66. ``` bash
  67. # From tensorflow/models/research/
  68. protoc object_detection/protos/*.proto --python_out=.
  69. ```
  70. **Note**: If you're getting errors while compiling, you might be using an incompatible protobuf compiler. If that's the case, use the following manual installation
  71. ## Manual protobuf-compiler installation and usage
  72. **If you are on linux:**
  73. Download and install the 3.0 release of protoc, then unzip the file.
  74. ```bash
  75. # From tensorflow/models/research/
  76. wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip
  77. unzip protobuf.zip
  78. ```
  79. Run the compilation process again, but use the downloaded version of protoc
  80. ```bash
  81. # From tensorflow/models/research/
  82. ./bin/protoc object_detection/protos/*.proto --python_out=.
  83. ```
  84. **If you are on MacOS:**
  85. If you have homebrew, download and install the protobuf with
  86. ```brew install protobuf```
  87. Alternately, run:
  88. ```PROTOC_ZIP=protoc-3.3.0-osx-x86_64.zip
  89. curl -OL https://github.com/google/protobuf/releases/download/v3.3.0/$PROTOC_ZIP
  90. sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
  91. rm -f $PROTOC_ZIP
  92. ```
  93. Run the compilation process again:
  94. ``` bash
  95. # From tensorflow/models/research/
  96. protoc object_detection/protos/*.proto --python_out=.
  97. ```
  98. ## Add Libraries to PYTHONPATH
  99. When running locally, the tensorflow/models/research/ and slim directories
  100. should be appended to PYTHONPATH. This can be done by running the following from
  101. tensorflow/models/research/:
  102. ``` bash
  103. # From tensorflow/models/research/
  104. export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
  105. ```
  106. Note: This command needs to run from every new terminal you start. If you wish
  107. to avoid running this manually, you can add it as a new line to the end of your
  108. ~/.bashrc file, replacing \`pwd\` with the absolute path of
  109. tensorflow/models/research on your system.
  110. # Testing the Installation
  111. You can test that you have correctly installed the Tensorflow Object Detection\
  112. API by running the following command:
  113. ```bash
  114. python object_detection/builders/model_builder_test.py
  115. ```