Introduction to tensorflow training model target detection and case analysis

Tensorflow added a lot of new features after updating version 1.0, which released a lot of deep network structure written by tf framework, which greatly reduced the development difficulty. With the ready-made network structure, it is convenient for fine-tuning or retraining. And TensorFlow includes a powerful object detection API that we can use to train our own data sets for special target detection. Recently, I finally ran the ssd_mobilenet_v1 model of the TensorFlow Object DetecTIon API. Here I recorded the whole process of how to run the data preparation to the model. I believe it will help everyone.

深度学习入门篇:手把手教你用 TensorFlow 训练模型

The Object DetecTIon API provides pre-training weights for five network structures, all of which are trained with data sets. These five models are SSD+mobilenet, SSD+incepTIon_v2, R-FCN+resnet101, faster RCNN+resnet101, and faster RCNN. +incepTIon+resnet101. The accuracy of each model and the time required for calculation are as follows. Here's how to use Object Detection to train your own model.

Introduction to Deep Learning: Teach you to use TensorFlow training model

The installation of TensorFlow is no longer explained here. There are a lot of online tutorials, and you can find a very detailed installation of TensorFlow documentation.

Tensorflow training model preparation before training

Use protobuf to configure the model and training parameters, so the API must be compiled first to compile the protobuf library. Here you can download the directly compiled pb library (https://github.com/google/protobuf/releases), after extracting the compressed package, Protoc is added to the environment variable:
$ cd tensorflow/models

$ protoc object_detection/protos/*.proto --python_out=.

(I added the protoc to the environment variable, I encountered an error that I could not find the *.proto file, and then put the protoc.exe in the models/object_detection directory and re-execute it)

Then add models and slim (tf advanced framework) to the python environment variable:
PYTHONPATH=$PYTHONPATH:/your/path/to/tensorflow/models:/your/path/to/tensorflow/models/slim

Tensorflow training model data preparation

The data set needs to be converted into a PASCAL VOC structure. The API provides create_pascal_tf_record.py to convert the VOC structure data set into a .record format. However, we found an easier way, Datitran provides a simpler way to produce .record format.

First you need to label the corresponding label first, here you can use the labelImg tool. Each time a sample is marked, an xml annotation file is generated. Then, put the labeled xml files into the two directories according to the training set and the verification set respectively. The xml_to_csv.py script is provided in Datitran. Just specify the directory name to be labeled here. Next, we need to convert the corresponding csv format to a .record format.

Introduction to Deep Learning: Teach you to use TensorFlow training model

Def main():
# image_path = os.path.join(os.getcwd(), 'annotations')
Image_path = r'D:raining-sets\object-detection\sunglasses\labelest'
Xml_df = xml_to_csv(image_path)
Xml_df.to_csv('sunglasses_test_labels.csv', index=None)
Print('Successfully converted xml to csv.')

Call generate_tfrecord.py, note the two parameters --csv_input and --output_path. Execute the following command:
Python generate_tfrecord.py --csv_input=sunglasses_test_labels.csv --output_path=sunglass_test.record

This generates train.record and test.record for training and validation. Next, specify the tag name, and follow the models/object_detection/data/ pet_label_map.pbtxt to recreate a file and specify the tag name.
Item {
Id: 1
Name: 'sunglasses'
}

Tensorflow training model training course

According to your own needs, choose a model pre-trained with coco dataset, put the prefix model.ckpt in the directory to be trained, where the meta file saves graph and metadata, ckpt saves the network's weights, these files represent The initial state of the pre-training model.

Open the ssd_mobilenet_v1_pets.config file and make the following changes:

Num_classes: modify to its own classes num

Introduction to Deep Learning: Teach you to use TensorFlow training model

Modify all PATH_TO_BE_CONFIGURED to the path you set before (5 in total)

Introduction to Deep Learning: Teach you to use TensorFlow training model

All other parameters remain the default parameters.

After preparing the above files, you can directly call the train file for training.
Python object_detection/train.py \
--logtostderr \
--pipeline_config_path= D:/training-sets /data-translate/training/ssd_mobilenet_v1_pets.config \
--train_dir=D:/training-sets/data-translate/training

TensorBoard Monitoring:

Through the tensorboard tool, you can monitor the training process. After entering the western command, enter localhost:6006 (default) in the browser.
Tensorboard --logdir= D:/training-sets/data-translate/training

Introduction to Deep Learning: Teach you to use TensorFlow training model

Introduction to Deep Learning: Teach you to use TensorFlow training model

Introduction to Deep Learning: Teach you to use TensorFlow training model

Lever Connector



Quick Wire Connector,Cable Plug-In Connector,Terminal Block Connector,Downlight led light connector,downlight terminal connector

Guangdong Ojun Technology Co., Ltd. , https://www.ojunconnector.com

This entry was posted in on