Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7dc4c94

Browse files
updated readme
1 parent 4915c84 commit 7dc4c94

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

‎README.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# How to train a custom object detection model with the Tensorflow Object Detection API
22
(ReadME inspired by [EdjeElectronics](https://github.com/EdjeElectronics))
33

4-
> Update: This README and Repository is now fully updated for Tensorflow 2. If you want to use Tensorflow 1 instead check out [my article](https://gilberttanner.com/blog/creating-your-own-objectdetector). If you want to train your model in Google Colab check out [my notebook](Tensorflow_2_Object_Detection_Train_model.ipynb).
4+
> Update: This README and Repository is now fully updated for Tensorflow 2. If you want to use Tensorflow 1 instead check out [my article](https://gilberttanner.com/blog/creating-your-own-objectdetector). If you want to train your model in Google Colab check out [the Tensorflow_2_Object_Detection_Train_model notebook](Tensorflow_2_Object_Detection_Train_model.ipynb).
55
66
![Example Output](doc/output.png)
77

@@ -93,11 +93,9 @@ OK (skipped=1)
9393

9494
Now that the Tensorflow Object Detection API is ready to go, we need to gather the images needed for training.
9595

96-
To train a robust model, we need lots of pictures that should vary as much as possible from each other. That means that they should have different lighting conditions, different backgrounds and lots of random objects in them.
96+
To train a robust model, the pictures should be as diverse as possible. So they should have different backgrounds, varying lighting conditions, and unrelated random objects in them.
9797

98-
You can either take the pictures yourself or you can download them from the internet. For my microcontroller detector, I have four different objects I want to detect (Arduino Nano, ESP8266, Raspberry Pi 3, Heltect ESP32 Lora).
99-
100-
I took about 25 pictures of each individual microcontroller and 25 pictures containing multiple microcontrollers using my smartphone. After taking the pictures make sure to transform them to a resolution suitable for training (I used 800x600).
98+
You can either take pictures yourself, or you can download pictures from the internet. For my microcontroller detector, I took about 25 pictures of each individual microcontroller and 25 pictures containing multiple microcontrollers.
10199

102100
![](doc/image_gallery.png)
103101

@@ -107,13 +105,13 @@ You can use the [resize_images script](resize_images.py) to resize the image to
107105
python resize_images.py -d images/ -s 800 600
108106
```
109107

110-
After you have all the images move about 80% to the object_detection/images/train directory and the other 20% to the object_detection/images/test directory. Make sure that the images in both directories have a good variety of classes.
108+
After you have all the images, move about 80% to the object_detection/images/train directory and the other 20% to the object_detection/images/test directory. Make sure that the images in both directories have a good variety of classes.
111109

112110
### 3. Labeling data
113111

114112
With all the pictures gathered, we come to the next step - labeling the data. Labeling is the process of drawing bounding boxes around the desired objects.
115113

116-
LabelImg is a great tool for creating a object detection data-set.
114+
LabelImg is a great tool for creating an object detection data-set.
117115

118116
[LabelImg GitHub](https://github.com/tzutalin/labelImg)
119117

@@ -123,13 +121,13 @@ Download and install LabelImg. Then point it to your images/train and images/tes
123121

124122
![label images](doc/label_image.png)
125123

126-
LabelImg supports two formats, PascalVOC and Yolo. For this tutorial make sure to select PascalVOC. LabelImg saves a xml file containing the label data for each image. These files will be used to create a tfrecord file, which can be used to train the model.
124+
LabelImg supports two formats, PascalVOC and Yolo. For this tutorial, make sure to select PascalVOC. LabelImg saves a xml file containing the label data for each image. These files will be used to create a tfrecord file, which can be used to train the model.
127125

128126
### 4. Generating Training data
129127

130-
With the images labeled, we need to create TFRecords that can be served as input data for training of the object detector. In order to create the TFRecords we will use two scripts from [Dat Tran’s raccoon detector](https://github.com/datitran/raccoon_dataset). Namely the xml_to_csv.py and generate_tfrecord.py files.
128+
With the images labeled, we need to create TFRecords that can be served as input data for training the object detector. To create the TFRecords, we will use two scripts from [Dat Tran’s raccoon detector](https://github.com/datitran/raccoon_dataset). Namely, the xml_to_csv.py and generate_tfrecord.py files.
131129

132-
After downloading both scripts we can first of change the main method in the xml_to_csv file so we can transform the created xml files to csv correctly.
130+
After downloading both scripts, we first change the main method in the xml_to_csv file to transform the created xml files to csv correctly.
133131

134132
```python
135133
# Old:
@@ -153,7 +151,7 @@ Now we can transform our xml files to csvs by opening the command line and typin
153151
python xml_to_csv.py
154152
```
155153

156-
These creates two files in the images directory. One called test_labels.csv and another one called train_labels.csv.
154+
The above command creates two files in the images directory. One called test_labels.csv and another one called train_labels.csv.
157155

158156
Next, open the generate_tfrecord.py file and replace the labelmap inside the class_text_to_int method with your own label map.
159157

@@ -193,7 +191,7 @@ python generate_tfrecord.py --csv_input=images/train_labels.csv --image_dir=imag
193191
python generate_tfrecord.py --csv_input=images/test_labels.csv --image_dir=images/test --output_path=test.record
194192
```
195193

196-
These two commands generate a train.record and a test.record file which can be used to train our object detector.
194+
These two commands generate a train.record and a test.record file, which can be used to train our object detector.
197195

198196
### 5. Getting ready for training
199197

@@ -226,7 +224,7 @@ The id number of each item should match the id of specified in the generate_tfre
226224

227225
#### 5.2 Creating the training configuration
228226

229-
Lastly we need to create a training configuration file. As a base model I will use EfficientDet – a recent family of SOTA models discovered with the help of Neural Architecture Search. The Tensorflow OD API provides a lot of different models. For more information check out the [Tensorflow 2 Detection Model Zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md)
227+
Lastly, we need to create a training configuration file. As a base model, I will use EfficientDet – a recent family of SOTA models discovered with the help of Neural Architecture Search. The Tensorflow OD API provides a lot of different models. For more information check out the [Tensorflow 2 Detection Model Zoo](https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf2_detection_zoo.md)
230228

231229
The [base config](https://github.com/tensorflow/models/blob/master/research/object_detection/configs/tf2/ssd_efficientdet_d0_512x512_coco17_tpu-8.config) for the model can be found inside the [configs/tf2 folder](https://github.com/tensorflow/models/tree/master/research/object_detection/configs/tf2).
232230

@@ -252,35 +250,35 @@ Copy the config file to the training directory. Then open it inside a text edito
252250

253251
* ```label_map_path: "<path>/labelmap.pbtxt"```
254252

255-
* Line 144 and 189: change batch_size to a number appropriate for your hardware, like 4, 8 or 16.
253+
* Line 144 and 189: change batch_size to a number appropriate for your hardware, like 4, 8, or 16.
256254

257255
### 6. Training the model
258256

259-
To train the model execute the following command in the command line:
257+
To train the model, execute the following command in the command line:
260258

261259
```bash
262260
python model_main_tf2.py --pipeline_config_path=training/ssd_efficientdet_d0_512x512_coco17_tpu-8.config --model_dir=training --alsologtostderr
263261
```
264262

265-
If everything was setup correctly the training should begin shortly and you should see something like the following:
263+
If everything was setup correctly, the training should begin shortly, and you should see something like the following:
266264

267265
![training the model](doc/training_model.png)
268266

269-
Every few minutes the current loss gets logged to Tensorboard. Open Tensorboard by opening a second command line, navigating to the object_detection folder and typing:
267+
Every few minutes, the current loss gets logged to Tensorboard. Open Tensorboard by opening a second command line, navigating to the object_detection folder and typing:
270268

271269
```tensorboard --logdir=training/train```
272270

273271
This will open a webpage at localhost:6006.
274272

275273
![monitor training](doc/monitor_training.png)
276274

277-
The training scrips saves checkpoints about every five minutes. Train the model until it reaches a satisfying loss then you can terminat the training process by pressing Ctrl+C.
275+
The training script saves checkpoints about every five minutes. Train the model until it reaches a satisfying loss, then you can terminate the training process by pressing Ctrl+C.
278276

279277
### 7. Exporting the inference graph
280278

281-
Now that we have a trained model we need to generate an inference graph, which can be used to run the model.
279+
Now that we have a trained model, we need to generate an inference graph that can be used to run the model.
282280

283-
> Note: There is currently a [issue](https://github.com/tensorflow/models/issues/8841) that occurs when you're trying to export the model. As a temprary fix Github user [Jacobsolawetz](https://github.com/Jacobsolawetz) discoverd that you can add ```if not isinstance(x, str):``` add line 140 of the ```https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/utils/tf_utils.py``` script. For more information check out [his comment to the issue](https://github.com/tensorflow/models/issues/8841#issuecomment-657647648).
281+
> Note: There is currently an [issue](https://github.com/tensorflow/models/issues/8841) that occurs when you're trying to export the model. As a temporary fix, Github user [Jacobsolawetz](https://github.com/Jacobsolawetz) discovered that you can add ```if not isinstance(x, str):``` add line 140 of the ```https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/utils/tf_utils.py``` script. For more information, check out [his comment on the issue](https://github.com/tensorflow/models/issues/8841#issuecomment-657647648).
284282
285283
```bash
286284
python /content/models/research/object_detection/exporter_main_v2.py \

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /