[] Pytorch-ssd target detection target detected data set produced a similar format pascal voc

pascal voc target detection data set in the following format:

among them:

  • Annotations for the image annotation information xml file
  • ImageSets training set, test set, verification, validation set of training images txt file name 
  • JPEGImages to the original picture

Pascal voc or yolo data format may be used for labeling labelimg: Download:

Link: https: //pan.baidu.com/s/1r8x7tu0sdO_UUuCXKVfELQ
extraction code: l325 

Very simple operation, not introduced.

Marked good xml file similar to the following:

<annotation>
    <folder>JPEGImages</folder>
    <filename>test_00000002.jpg</filename>
    <path>E:\detection\pascal voc\maskornot\JPEGImages\test_00000002.jpg</path>
    <source>
        <database>Unknown</database>
    </source>
    <size>
        <width>480</width>
        <height>600</height>
        <depth>3</depth>
    </size>
    <segmented>0</segmented>
    <object>
        <name>mask</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>112</xmin>
            <ymin>7</ymin>
            <xmax>352</xmax>
            <ymax>325</ymax>
        </bndbox>
    </object>
</annotation>

An image corresponding follows:

Then divide the training set, test set, validation set, validation set of training: focused on the original VOC2007 data, trainval accounts for about 50% of the entire data set, test about 50% of the entire data set; train of about 50% trainval, val of about 50% trainval

import os
import random
 
trainval_percent = 0.5
train_percent = 0.5
xmlfilepath = '/content/drive/My Drive/pytorch_ssd/data/maskornot/Annotations'
txtsavepath = '/content/drive/My Drive/pytorch_ssd/data/maskornot/ImageSets/Main'
total_xml = os.listdir(xmlfilepath)
 
num=len(total_xml)
list=range(num)
tv=int(num*trainval_percent)
tr=int(tv*train_percent)
trainval= random.sample(list,tv)
train=random.sample(trainval,tr)
 
ftrainval = open(txtsavepath+'/trainval.txt', 'w')
ftest = open(txtsavepath+'/test.txt', 'w')
ftrain = open(txtsavepath+'/train.txt', 'w')
fval = open(txtsavepath+'/val.txt', 'w')
 
for i  in list:
  name=total_xml[i][:-4]+'\n'
  if i in trainval:
      ftrainval.write(name)
      if i in train:
          ftrain.write(name)
      else:
          fval.write(name)
  else:
      ftest.write(name)
 
ftrainval.close()
ftrain.close()
fval.close()
ftest.close()

After running:

Wherein tranval.txt partial result is:

test_00000002 
test_00000003 
test_00000006 
test_00000009 
test_00000008 
test_00000012 
test_00000013 
test_00000014 
test_00000020

At this point, create target detection data set is complete.

 

The next section, using pytorch-ssd training to create their own data sets.

Guess you like

Origin www.cnblogs.com/xiximayou/p/12546061.html