pythoncaffelmdb

how to convert the annotation.xml files into train.txt and val.txt for object detection?


I'm training custom image data sets for object detection using caffe. Here i have train and validation directory. By using LabelImg , the object annotation created in a .xml file for each image separately (image1.xml,image2.xml etc.). Now i want to convert all this xml files into train.txt and val.txt. How can i do it? I stuck in this step since 3 weeks

218.xml

`<annotation>
    <folder>train</folder>
    <filename>218</filename>
    <path>C:\kp\images\train\218.jpg</path>
    <source>
        <database>Unknown</database>
    </source>
    <size>
        <width>352</width>
        <height>288</height>
        <depth>3</depth>
    </size>
    <segmented>0</segmented>
    <object>
        <name>person</name>
        <pose>Unspecified</pose>
        <truncated>0</truncated>
        <difficult>0</difficult>
        <bndbox>
            <xmin>79</xmin>
            <ymin>56</ymin>
            <xmax>262</xmax>
            <ymax>283</ymax>
        </bndbox>
    </object>
</annotation>`

For each image i have created annotation.xml file (image_name.xml) by using the tool. Now i need to convert it into train.txt and val.txt for input to the create LMDB. I have already gone through Caffe LMDB train and val.txt , how to make train.txt file in caffe , A guide to convert_imageset.cpp , https://github.com/chuanqi305/MobileNet-SSD/issues/90

But everything is for object classification and and others didn't explain it too.. Any suggestions or help will be appreciated


Solution

  • train.txt

    imagepath xmlpath

    image/image1.jpg label/image1.xml
    image/image2.jpg label/image2.xml
    image/image3.jpg label/image3.xml
    image/image4.jpg label/image4.xml
    ...
    

    this is train.txt or test.txt