balancap / SSD-Tensorflow

Single Shot MultiBox Detector in TensorFlow
4.11k stars 1.89k forks source link

Where is wrong on my step to train on my own dataset that i process with Voc2007/ #265

Closed lzzzzzzzzz closed 4 months ago

lzzzzzzzzz commented 6 years ago

1.I download the Voc2007 dataset and process the dataset with a py file.The dataset change the 20 classes to one class 2.chage the param ssd_vgg_300.py line 94 default_params = SSDParams( img_shape=(300, 300), num_classes=2, no_annotation_label=2,....) pascalvoc_common.py VOC_LABELS = { 'none': (0, 'Background'), 'person': (1, 'Person'), } pascalvoc_2007.py TRAIN_STATISTICS = { 'none': (0, 0), 'person': (2008, 4690), } TEST_STATISTICS = { 'none': (0, 0), 'person': (1, 1), 'total': (1, 1), } SPLITS_TO_SIZES = { 'train': 2096, 'test': 2096, } SPLITS_TO_STATISTICS = { 'train': TRAIN_STATISTICS, 'test': TEST_STATISTICS, } NUM_CLASSES = 1 train_ssd_netword.py --train_dir=./train_model --dataset_dir=./tfrecords --dataset_name=pascalvoc_2007 --dataset_split_name=train --model_name=ssd_300_vgg --save_summaries_secs=60 --save_interval_secs=600 --weight_decay=0.0005 --optimizer=adam --learning_rate=0.00001 --learning_rate_decay_factor=0.94 --batch_size=8 --num_classes=2 --gpu_memory_fraction=0.7

after the training has finished,I test the image,but there is nothing on image. Can somebody tell me where I am wrong?I will appricate for your help.

lzzzzzzzzz commented 6 years ago

here is the code i process the VOC2007 dataset

import os import xml.dom.minidom import re import random

def screenout(VOCpath,classes):

filepath = os.path.join(VOCpath, 'Annotations')
filelist = os.listdir(filepath)
for file in filelist:
    xmlfilepath = os.path.join(filepath, file)
    xmlfile = xml.dom.minidom.parse(xmlfilepath)

    annotation = xmlfile.getElementsByTagName('annotation')[0]

    objects = xmlfile.getElementsByTagName('object')
    for object in objects:
        for node in object.childNodes:
            if node.nodeValue == None and node.nodeName == 'name' and node.firstChild.data != classes:
                annotation.removeChild(object)

    if objects == []:
        picpath = str(os.path.join(VOCpath, 'JPEGImages')) + str(file.split('.')[0]) + '.jpg'
        os.remove(xmlfilepath)
        os.remove(picpath)
        print('-------------------------')
        print('delete xmlfile:' + xmlfilepath)
        print('delete jpeg:' + picpath)
        print('-------------------------')
    else:

        xmlstr = xmlfile.toxml()
        xmlstr = re.sub(pattern='<?.*?>', repl='', string=xmlstr, count=1)
        f = open(xmlfilepath, 'w')
        f.write(xmlstr)
        f.close()
        print('*************************')
        print('handing xmlfile:' + xmlfilepath)
        print('delete useless <object>***</object>')
        print('*************************')

def rename(VOCpath): annotationpath = os.path.join(VOCpath,'Annotations') jpegpath = os.path.join(VOCpath,'JPEGImages')

annotationlist = os.listdir(annotationpath)
i = 1
n = 6
for file in annotationlist:
    n = 6 - len(str(i))
    before = os.path.join(annotationpath,file)
    after = os.path.join(annotationpath,str(0) * n + str(i) + '.xml')
    os.rename(before,after)
    print('converting %s to %s ...' % (before, after))

    before = os.path.join(jpegpath, str(file.split('.')[0]) + '.jpg')
    after = os.path.join(jpegpath,str(0) * n + str(i) + '.jpg')
    os.rename(before,after)
    print('converting %s to %s ...' % (before, after))
    i += 1

def makeMain(VOCpath, trainval_percent=0.66, train_percent=0.5): xmlfilepath = os.path.join(VOCpath, 'Annotations') txtsavepath = os.path.join(VOCpath, '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(os.path.join(txtsavepath, 'trainval.txt'), 'w')
ftest = open(os.path.join(txtsavepath, 'test.txt'), 'w')
ftrain = open(os.path.join(txtsavepath, 'train.txt'), 'w')
fval = open(os.path.join(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()

if name == 'main':

screenout('..\VOC2007','person')

# rename('..\VOC2007')
makeMain('..\VOC2007')