This article refers to http://blog.csdn.net/Numeria/article/details/73604339
and reference to open source code github Links: https://github.com/BartyzalRadek/Multi-label-Inception-net One, prepare training data
1. Download Data set
This article uses the open source data set of Nanjing University (click to download: Http://lamda.nju.edu.cn/files/miml-image-data.rar)
The dataset contains 2000 images, 5 classes, namely desert, mountains, sea, sunset, trees.
Contains two compressed packages after download: Original.rar and Processed.rar
Original.rar contains 2000 image data
Examples are as follows:
The Processed.rar contains the corresponding label information for the image.
After decompression for the MATLAB file format.
What this paper needs is the tag matrix Target.mat
Examples are as follows:
2. Convert label file
This article needs to convert Target.mat to TXT format label file.
For each image imagename.jpg, the corresponding generation of a imagename.jpg.txt label file, the file contains the label of each behavior image.
For the image to the left of the following figure, with the label Desert,mountains, the corresponding label file contents are shown on the right.
For Target.mat files, transform the Matlab script as follows:
Load (' Miml data.mat ');
If ~exist (' Labeldir ')
mkdir labeldir;
End
labeldir= ' labeldir/';
For i = 1:2000
stri = Num2str (i);
Label_file_name = [Labeldir stri '. Jpg.txt '];
FID = fopen (label_file_name, ' W ');
for j = 1:5
if targets (j,i) ==1
fprintf (FID, '%s\n ', class_name{j});
End
End
fclose (FID);
End
1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16
After processing the file is: Https://pan.baidu.com/s/1pLoeC6R two, multiple label classification
This article uses the trained weights to replace the last layer with the number of categories in the custom dataset, the front weights unchanged, and only the last layer is trained.
1. Put the folder containing all the images in the Multi-label-inception-net/images directory
2. Copy the Labeldir directory to the Multi-label-inception-net directory and change the name to Image_labels_dir (replace the original directory with the same name)
3. Run the Python script
Python retrain.py \
--bottleneck_dir=bottlenecks \
--how_many_training_steps \
--model_dir=model_ DIR \
--output_graph=retrained_graph.pb \
--output_labels=retrained_labels.txt \
--summaries_dir= Retrain_logs \
--image_dir=images
1 2 3 4 5 6 7 8
Start training
Training completed
third, image prediction
Using script label_image.py to predict images
The call is as follows:
Python label_image.py images/image/4.jpg
1
Get output results:
Copyright NOTICE: This article is the original article of the blogger, without the permission of the blogger may not be reproduced.