You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+64-15Lines changed: 64 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -6,27 +6,30 @@
6
6
### Introduction
7
7
8
8
9
-
With the [announcement](https://blog.tensorflow.org/2020/07/tensorflow-2-meets-object-detection-api.html) that Object Detection API is now compatible with Tensorflow 2, I tried to test the new models published in the [TF2 model zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md), and train them with my custom data. However, I have faced some problems as the scripts I have for Tensorflow 1 is not working with Tensorflow 2 (which is not surprising!), in addition to having very poor documentation and tutorials from tensorflow models repo. Therefore, in this repo I am sharing my experience, in addition to providing clean codes to run the inference and training object detection models using Tensorflow 2.
9
+
With the [announcement](https://blog.tensorflow.org/2020/07/tensorflow-2-meets-object-detection-api.html) that [Object Detection API](https://github.com/tensorflow/models/tree/master/research/object_detection) is now compatible with Tensorflow 2, I tried to test the new models published in the [TF2 model zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md), and train them with my custom data.
10
+
However, I have faced some problems as the scripts I have for Tensorflow 1 is not working with Tensorflow 2 (which is not surprising!), in addition to having very poor documentation and tutorials from tensorflow models repo.
11
+
In this repo I am sharing my experience, in addition to providing clean codes to run the inference and training object detection models using Tensorflow 2.
10
12
11
-
This tutorial should be useful for those who has experience with the API but cannot find clear documentation or examples for the new changes to use it with Tensorflow 2. However, I will add all the details and working examples for the new comers who are trying to use the object detection api for the first time, so hopefully this tutorial will make it easy for beginners to get started and run their object detection models easily.
13
+
This tutorial should be useful for those who have experience with the API but cannot find clear examples for the new changes to use it with Tensorflow 2.
14
+
However, I will add all the details and working examples for the new comers who are trying to use the object detection api for the first time, so hopefully this tutorial will make it easy for beginners to get started and run their object detection models easily.
12
15
13
16
14
17
### Roadmap
15
18
16
19
This tutorial should take you from installation, to running pre-trained detection model, and training/evaluation your models with a custom dataset.
17
20
18
21
1.[Installation](#installation)
19
-
2. Inference with pre-trained models
22
+
2.[Inference with pre-trained models](#inference-with-pre-trained-models)
20
23
3. Preparing your custom dataset for training
21
24
4. Training with your custom data, and exporting trained models for inference
22
25
23
26
### Installation
24
27
25
28
The examples in this repo is tested with python 3.6 and Tensorflow 2.2.0, but it is expected to work with other Tensorflow 2.x versions with python version 3.5 or higher.
26
29
27
-
It is recommended to install [anaconda](https://www.anaconda.com/products/individual) and create new environment for your project:
30
+
It is recommended to install [anaconda](https://www.anaconda.com/products/individual) and create new [environment](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html) for your projects that use the installed packages:
28
31
29
-
```
32
+
```bash
30
33
# create new environment
31
34
conda create --name py36-tf2 python=3.6
32
35
@@ -36,15 +39,15 @@ conda activate py36-tf2
36
39
37
40
You need first to install tensorflow 2, either with GPU or CPU only support (slow). For Installation with GPU support, you need to have CUDA 10.1 with CUDNN 7.6 to use Tensorflow 2.2.0. You can check the compatible versions of any tensorflow version with cuda and cudnn versions from [here](https://www.tensorflow.org/install/source#tested_build_configurations).
38
41
39
-
```
42
+
```bash
40
43
# if you have NVIDIA GPU with cuda 10.1 and cudnn 7.6
41
44
pip install tensorflow-gpu==2.2.0
42
45
```
43
46
44
47
A great feature of Anaconda is that it can automatically install a local version of cudatoolkit that is compatible with your tensorflow version (But you should have the proper nvidia gpu drivers installed).
45
48
46
-
```
47
-
# installation from anaconda along with cudatoolkit
49
+
```bash
50
+
# installation from anaconda along with cudatoolkit (tf2 version 2.2.0)
48
51
conda install -c anaconda tensorflow-gpu==2.2.0
49
52
50
53
# or to install latest version of tensorflow, just type
After that, you should install the object detection api itself, which became much easier now after the latest update. The official installation instructions can be found [here](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2.md), but I will add the instruction to install it as a python package.
64
+
After that, you should install the object detection api itself, which became much easier now after the latest update.
65
+
The official installation instructions can be found [here](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2.md), but I will add here the instruction to install it as a python package.
The previous commands installs the object detection api as a python package that will be available in your virtual environmnet (if you created one), and will automatically install all required dependencies if not found.
88
+
The previous commands installs the object detection api as a python package that will be available in your virtual environmnet (if you created one), and will automatically install all required dependencies if not already installed.
85
89
86
90
Finally, to test that your installation is correct, type the following command:
For more installation options, please refer to the original [installation guide](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2.md).
98
+
93
99
94
100
### Inference with pre-trained models
95
101
96
-
TODO
102
+
To go through the tutorial, clone this repo and follow the instructions step by step.
To get started with the Object Detection API with TF2, let's download one of the models pre-trained with coco dataset from the [tf2 detection model zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md), and use it for inference.
110
+
111
+
You can download any of the models from the table in the [model zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md), and place it in the [models/](models) directory. For example, let's download the EfficientDet D0 model.
In the tensorflow object detection repo, they provide a tutorial for inference in this [notebook](https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/inference_from_saved_model_tf2_colab.ipynb), but it is not so clean and needs many improvements.
122
+
Therefore, I have created a [class for object detection inference](detector.py), along with an [example script](detect_objects.py) to use this class to run the inference with input images, or from a video.
123
+
124
+
I encourage you to have a look at the [class file](detector.py) and the [example script](detect_objects.py) and adapt it to your application. But let's first see how to use it to get the inference running with the EfficientDet D0 model we just downloaded.
125
+
126
+
We can provide some argument when running the scripts, first the `--model_path` argument for the path of the trained model, and the `--path_to_labelmap` for the labelmap file of your dataset (here we use the one for coco dataset).
127
+
To run the detection with set of images, provide a path to the folder containing the images in the argument `--images_dir`.
You can also select set of classes to be detected by passing their labels to the argument `--class_ids` as a string with the "," delimiter. For example, using `--class_ids "1,3" ` will do detection for the classes "person" and "car" only as they have id 1 and 3 respectively (you can check the id and labels from the [coco labelmap](models/mscoco_label_map.pbtxt)). Not using this argument will lead to detecting all objects in the provided labelmap.
139
+
140
+
Let's use video input by enabling the flag `--video_input`, in addition to detecting only people by passing id 1 to the `--class_ids` argument. The video used for testing is downloaded from [here](https://www.youtube.com/watch?v=pk96gqasGBQ).
0 commit comments