예제 #1
0
def saveVideoResults(filename, annotations):
    if not os.path.exists(filename):
        print(("Created File: " + filename))
    file = open(filename, 'w')
    for annotation in annotations:
        frame = -1
        trackID = -1
        conf = 0
        silhouette = -1
        xmin, ymin, xmax, ymax = 0, 0, 0, 0

        detections_array = []

        if annotation.frame is not -1:
            frame = annotation.frame
        for rect in annotation.rects:
            if vid_classes.class_string_to_comp_code(
                    rect.label) is not 'nothing':
                silhouette = rect.label
            if rect.trackID is not -1:
                trackID = rect.trackID
            conf = rect.true_confidence
            xmin, ymin, xmax, ymax = rect.x1, rect.y1, rect.x2, rect.y2
            file.write(
                str(frame) + ' ' + str(silhouette) + ' ' + str(trackID) + ' ' +
                str(conf) + ' ' + str(xmin) + ' ' + str(ymin) + ' ' +
                str(xmax) + ' ' + str(ymax) + os.linesep)
    file.close()
def parse_XML_to_data(xml_list_video):
    frames_list=[]
    video_list=[]
    # image_multi_class= None
    # rectangle_multi = None
    progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()])
    for i in progress(range(0, len(xml_list_video))):
        # print "Iterating on Video:"+ str(xml_list_video[i][0][0])
        for j in range(0, len(xml_list_video[i])):
            # print "Iterating on Frame:"+ str(xml_list_video[i][j][0])
            with open(xml_list_video[i][j][0], 'rt') as f:
                tree = ElementTree.parse(f)
                for obj in tree.findall('object'):                
                    name = obj.find('name').text
                    class_code= name
                    name = vid_classes.code_to_class_string(name)
                    if name in ["nothing"]:
                        continue
                    else:
                        #The files with the original data path are made in both: multiclass e single class
                        jump=0
                        image_multi_class= fm.Frame_Info()
                        image_multi_class.frame= xml_list_video[i][j][1]
                        # print image_multi_class.frame
                        rectangle_multi= multiclass_rectangle.Rectangle_Multiclass()
                        for node in tree.iter():
                            tag=str(node.tag)
                            if tag in ['name']:
                                if str(vid_classes.code_to_class_string(str(node.text))) in ["nothing"]:
                                    jump = 1
                                else : 
                                    jump=0
                                    rectangle_multi.label_chall=int(vid_classes.class_string_to_comp_code(str(vid_classes.code_to_class_string(str(node.text)))))
                                    # print rectangle_multi.label_chall
                                    rectangle_multi.label_code=str(node.text)
                                    rectangle_multi.label=vid_classes.code_to_class_string(str(node.text))                                
                            if tag in ["xmax"]:
                                if jump == 0:
                                    rectangle_multi.x2=float(node.text)
                            if tag in ["xmin"]:
                                if jump == 0:
                                    rectangle_multi.x1=float(node.text)
                            if tag in ["ymax"]:
                                if jump == 0:
                                    rectangle_multi.y2=float(node.text)                            
                            if tag in ["ymin"]:
                                if jump == 0:    
                                    rectangle_multi.y1=float(node.text)
                                    image_multi_class.append_rect(rectangle_multi)
                        if jump == 0:
                            image_multi_class.append_labeled_rect(rectangle_multi)
                        break
                frames_list.append(image_multi_class)
        video_list.append(frames_list)
        # frames_list=None
        # frames_list=[]        
    return video_list
예제 #3
0
def parse_XML_to_data(xml_list_video):
    frames_list=[]
    video_list=[]
    # image_multi_class= None
    # rectangle_multi = None
    progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()])
    for i in progress(list(range(0, len(xml_list_video)))):
        # print "Iterating on Video:"+ str(xml_list_video[i][0][0])
        for j in range(0, len(xml_list_video[i])):
            # print "Iterating on Frame:"+ str(xml_list_video[i][j][0])
            with open(xml_list_video[i][j][0], 'rt') as f:
                tree = ElementTree.parse(f)
                for obj in tree.findall('object'):                
                    name = obj.find('name').text
                    class_code= name
                    name = vid_classes.code_to_class_string(name)
                    if name in ["nothing"]:
                        continue
                    else:
                        #The files with the original data path are made in both: multiclass e single class
                        jump=0
                        image_multi_class= fm.Frame_Info()
                        image_multi_class.frame= xml_list_video[i][j][1]
                        # print image_multi_class.frame
                        rectangle_multi= multiclass_rectangle.Rectangle_Multiclass()
                        for node in tree.iter():
                            tag=str(node.tag)
                            if tag in ['name']:
                                if str(vid_classes.code_to_class_string(str(node.text))) in ["nothing"]:
                                    jump = 1
                                else : 
                                    jump=0
                                    rectangle_multi.label_chall=int(vid_classes.class_string_to_comp_code(str(vid_classes.code_to_class_string(str(node.text)))))
                                    # print rectangle_multi.label_chall
                                    rectangle_multi.label_code=str(node.text)
                                    rectangle_multi.label=vid_classes.code_to_class_string(str(node.text))                                
                            if tag in ["xmax"]:
                                if jump == 0:
                                    rectangle_multi.x2=float(node.text)
                            if tag in ["xmin"]:
                                if jump == 0:
                                    rectangle_multi.x1=float(node.text)
                            if tag in ["ymax"]:
                                if jump == 0:
                                    rectangle_multi.y2=float(node.text)                            
                            if tag in ["ymin"]:
                                if jump == 0:    
                                    rectangle_multi.y1=float(node.text)
                                    image_multi_class.append_rect(rectangle_multi)
                        if jump == 0:
                            image_multi_class.append_labeled_rect(rectangle_multi)
                        break
                frames_list.append(image_multi_class)
        video_list.append(frames_list)
        # frames_list=None
        # frames_list=[]        
    return video_list
def saveVideoResults(filename, annotations):
    if not os.path.exists(filename):
        print "Created File: "+ filename
    file = open(filename, 'w')
    for annotation in annotations:
        frame = -1
        trackID=-1
        conf=0
        silhouette=-1
        xmin,ymin,xmax,ymax=0,0,0,0

        detections_array=[]

        if annotation.frame is not -1:
            frame=annotation.frame
        for rect in annotation.rects:
            if vid_classes.class_string_to_comp_code(rect.label) is not 'nothing':
                silhouette=rect.label
            if rect.trackID is not -1:
                trackID=rect.trackID
            conf = rect.true_confidence
            xmin,ymin,xmax,ymax = rect.x1,rect.y1,rect.x2 ,rect.y2
            file.write(str(frame)+' '+str(silhouette)+' '+str(trackID)+' '+str(conf)+' '+str(xmin)+' '+str(ymin)+' '+str(xmax)+' '+str(ymax) + os.linesep)
    file.close()
예제 #5
0
def parse_XML_lightweight_txt(bb_XML_file_list, path_val_folder, path_dataset):

    count_rect = 0
    count_img = 0

    progress = progressbar.ProgressBar(widgets=[
        progressbar.Bar('=', '[', ']'), ' ',
        progressbar.Percentage(), ' ',
        progressbar.ETA()
    ])

    print "Start Processing & Building Dataset... may take a while..."

    path_mltcl_bb_file = path_dataset + '/' + string_mltcl_bb_file  # Create this file in .dataset/airplane/airplane_bb_mltcl_file_list.txt
    path_mltcl_class_code_file = path_dataset + '/' + string_mltcl_class_code_file
    path_mltcl_class_name_file = path_dataset + '/' + string_mltcl_class_name_file
    path_mltcl_chall_code_file = path_dataset + '/' + string_mltcl_chall_code_file

    for file_name in progress(bb_XML_file_list):
        with open(file_name, 'rt') as f:
            tree = ElementTree.parse(f)
            for obj in tree.findall('object'):
                name = obj.find('name').text
                class_code = name
                name = vid_classes.code_to_class_string(name)

                if name in ["nothing"]:
                    continue
                else:

                    same_label = 0
                    #The files with the original data path are made in both: multiclass e single class

                    path_bb_file = path_dataset + '/' + name + '/' + name + string_bb_file
                    path_class_code_file = path_dataset + '/' + name + '/' + name + string_class_code_file
                    path_class_name_file = path_dataset + '/' + name + '/' + name + string_class_name_file
                    path_chall_code_file = path_dataset + '/' + name + '/' + name + string_chall_code_file

                    path_orig_file = path_val_folder

                    jump = 0

                    image_single_class = Frame_Info()
                    image_single_class.dataset_path = path_val_folder

                    image_multi_class = Frame_Info()
                    image_multi_class.dataset_path = path_val_folder

                    rectangle_single = Rectangle_Multiclass()
                    rectangle_multi = Rectangle_Multiclass()

                    #xmin x1 letf
                    #ymin y1 bottom
                    #xmax x2 right
                    #ymax y2 top

                    for node in tree.iter():
                        tag = str(node.tag)

                        if tag in ["folder"]:
                            path_orig_file = path_orig_file + '/' + str(
                                node.text)
                            image_single_class.folder = str(node.text)
                            image_multi_class.folder = str(node.text)

                        if tag in ["filename"]:
                            image_single_class.filename = str(
                                node.text) + '.PNG'
                            image_multi_class.filename = str(
                                node.text) + '.PNG'

                            path_orig_file = path_orig_file + '/' + str(
                                node.text) + '.JPEG'

                        if tag in ['name']:
                            if str(
                                    vid_classes.code_to_class_string(
                                        str(node.text))) in ["nothing"]:
                                jump = 1
                            else:
                                jump = 0
                                rectangle_multi.label_chall = int(
                                    vid_classes.class_string_to_comp_code(
                                        str(
                                            vid_classes.code_to_class_string(
                                                str(node.text)))))
                                rectangle_multi.label_code = str(node.text)
                                rectangle_multi.label = vid_classes.code_to_class_string(
                                    str(node.text))

                                if str(node.text) == class_code:
                                    same_label = 1
                                    rectangle_single.label_chall = int(
                                        vid_classes.class_string_to_comp_code(
                                            str(
                                                vid_classes.
                                                code_to_class_string(
                                                    str(node.text)))))
                                    rectangle_single.label_code = str(
                                        node.text)
                                    rectangle_single.label = vid_classes.code_to_class_string(
                                        str(node.text))
                                else:
                                    same_label = 0

                        if tag in ["xmax"]:
                            if jump == 0:
                                rectangle_multi.x2 = float(
                                    utils_image.transform_point(
                                        image_multi_class.width,
                                        image_multi_class.height, width,
                                        height, float(node.text), False))
                                if same_label == 1:
                                    rectangle_single.x2 = float(
                                        utils_image.transform_point(
                                            image_multi_class.width,
                                            image_multi_class.height, width,
                                            height, float(node.text), False))
                        if tag in ["xmin"]:
                            if jump == 0:
                                rectangle_multi.x1 = float(
                                    utils_image.transform_point(
                                        image_multi_class.width,
                                        image_multi_class.height, width,
                                        height, float(node.text), False))
                                if same_label == 1:
                                    rectangle_single.x1 = float(
                                        utils_image.transform_point(
                                            image_multi_class.width,
                                            image_multi_class.height, width,
                                            height, float(node.text), False))
                        if tag in ["ymax"]:
                            if jump == 0:
                                rectangle_multi.y2 = float(
                                    utils_image.transform_point(
                                        image_multi_class.width,
                                        image_multi_class.height, width,
                                        height, float(node.text), False))
                                image_multi_class.append_rect(rectangle_multi)
                                count_rect = count_rect + 1
                                if same_label == 1:
                                    rectangle_single.y2 = float(
                                        utils_image.transform_point(
                                            image_multi_class.width,
                                            image_multi_class.height, width,
                                            height, float(node.text), False))
                                    image_single_class.append_rect(
                                        rectangle_single)
                        if tag in ["ymin"]:
                            if jump == 0:
                                rectangle_multi.y1 = float(
                                    utils_image.transform_point(
                                        image_multi_class.width,
                                        image_multi_class.height, width,
                                        height, float(node.text), False))
                                if same_label == 1:
                                    rectangle_single.y1 = float(
                                        utils_image.transform_point(
                                            image_multi_class.width,
                                            image_multi_class.height, width,
                                            height, float(node.text), False))

                    if jump == 0:

                        count_img = count_img + 1

                        out_stream = open(path_mltcl_bb_file, "a")
                        out_stream.write(image_multi_class.get_info_string() +
                                         os.linesep)

                        out_stream = open(path_mltcl_class_code_file, "a")
                        out_stream.write(image_multi_class.get_rects_code() +
                                         os.linesep)

                        out_stream = open(path_mltcl_class_name_file, "a")
                        out_stream.write(image_multi_class.get_rects_labels() +
                                         os.linesep)

                        out_stream = open(path_mltcl_chall_code_file, "a")
                        out_stream.write(image_multi_class.get_rects_chall() +
                                         os.linesep)

                        if same_label == 1:
                            out_stream = open(path_bb_file, "a")
                            out_stream.write(
                                image_single_class.get_info_string() +
                                os.linesep)

                            out_stream = open(path_class_code_file, "a")
                            out_stream.write(
                                image_single_class.get_rects_chall() +
                                os.linesep)

                            out_stream = open(path_class_name_file, "a")
                            out_stream.write(
                                image_single_class.get_rects_labels() +
                                os.linesep)

                            out_stream = open(path_chall_code_file, "a")
                            out_stream.write(
                                image_single_class.get_rects_code() +
                                os.linesep)
                    break
    print "SUMMARY:"
    print "Parsed: %d BB Files" % len(bb_XML_file_list)
    print "Added: %d Object Rectangles" % count_rect
    print "Added: %d Images" % count_img
    if count_img > 0:
        print "Ratio BB_Files/Images: %.2f" % (float(count_img) /
                                               float(len(bb_XML_file_list)))
    if count_rect > 0:
        print "Ratio Images/Object_Rectangles: %.2f" % (float(count_img) /
                                                        float(count_rect))
def parse_XML_to_singleclass_txt(bb_XML_file_list, path_val_folder, path_dataset):

    with open('dataset/summary.txt', 'w') as summary:
        for class_name in CL.class_name_string_list:

            print "Starting making files for class:%s , May take a while.... "%class_name 

            progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()])
            path_bb_file=path_dataset+'/'+class_name+'/'+ class_name+string_bb_file
            path_class_code_file= path_dataset+'/'+class_name+'/'+class_name+string_class_code_file
            path_class_name_file= path_dataset+'/'+class_name+'/'+class_name+string_class_name_file
            path_chall_code_file= path_dataset+'/'+class_name+'/'+class_name+string_chall_code_file
            count_rect=0
            count_img=0
            for file_name in progress(bb_XML_file_list):
                with open(file_name, 'rt') as f:
                    tree = ElementTree.parse(f)
                    for obj in tree.findall('object'):
                        name = obj.find('name').text
                        class_code= name
                        name = vid_classes.code_to_class_string(name)

                        if name in ["nothing"]:
                            continue
                        else:

                            same_label=0
                            
                            image_single_class= Frame_Info()
                            image_single_class.dataset_path= path_val_folder
                            path_orig_file=path_val_folder

                            rectangle_single= Rectangle_Multiclass()
                            
                            #xmin x1 letf
                            #ymin y1 bottom
                            #xmax x2 right
                            #ymax y2 top
                        
                            for node in tree.iter():
                                tag=str(node.tag)
                    
                                if tag in ["folder"]:
                                    path_orig_file=path_orig_file+'/'+str(node.text)
                                    image_single_class.folder= str(node.text)
                                if tag in ["filename"]:
                                    image_single_class.filename=str(node.text)+'.PNG'
                                    path_orig_file=path_orig_file+'/'+str(node.text)+'.JPEG'

                                if tag in ["width"]:
                                    image_single_class.width= int(node.text)

                                if tag in ["height"]:
                                    image_single_class.height= int(node.text)

                                if tag in ["trackid"]:
                                    image_single_class.frame= int(os.path.basename(file_name).replace('.xml', ''))

                                if tag in ['name']:
                                    if str(vid_classes.code_to_class_string(str(node.text))) in ["nothing"]: 
                                        jump = 1
                                    if str(vid_classes.code_to_class_string(str(node.text))) is not class_name:
                                        jump = 1
                                    else : 
                                        jump=0
                                        rectangle_single.label_chall=int(vid_classes.class_string_to_comp_code(str(vid_classes.code_to_class_string(str(node.text)))))
                                        rectangle_single.label_code=str(node.text)
                                        rectangle_single.label=vid_classes.code_to_class_string(str(node.text))
                                if tag in ["xmax"]:
                                    if jump == 0:
                                        rectangle_single.x2=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),True))
                                if tag in ["xmin"]:
                                    if jump == 0:
                                        rectangle_single.x1=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),True))
                                if tag in ["ymin"]:
                                    if jump == 0:
                                        rectangle_single.y1=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),False))
                                if tag in ["ymax"]:
                                    if jump == 0:    
                                        rectangle_single.y2=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),False))
                                        image_single_class.append_rect(rectangle_single)
                                        count_rect=count_rect+1

                            if jump == 0:
                                
                                count_img=count_img+1
                                out_stream = open(path_bb_file, "a")
                                out_stream.write(image_single_class.get_info_string()+ os.linesep)
                                
                                out_stream = open(path_class_code_file, "a")
                                out_stream.write(image_single_class.get_rects_chall()+ os.linesep)
                                
                                out_stream = open(path_class_name_file, "a")
                                out_stream.write(image_single_class.get_rects_labels()+ os.linesep)
                                
                                out_stream = open(path_chall_code_file, "a")
                                out_stream.write(image_single_class.get_rects_code() + os.linesep)

                            break
            summary.write( ("Ended with Success Process for class:%s"%class_name )+os.linesep +"SUMMARY:" + os.linesep+ ("Parsed: %d BB Files"%len(bb_XML_file_list)) + os.linesep+ ("Added: %d Object Rectangles"%count_rect) + os.linesep+("Added: %d Images"%count_img)+os.linesep)
            print "Ended with Success Process for class:%s"%class_name 
            print "SUMMARY:"
            print "Parsed: %d BB Files"%len(bb_XML_file_list)
            print "Added: %d Object Rectangles"%count_rect
            print "Added: %d Images"%count_img
            if count_img>0: 
                print "Ratio BB_Files/Images: %.2f"%(float(count_img)/float(len(bb_XML_file_list)))
                summary.write(("Ratio BB_Files/Images: %.2f"%(float(count_img)/float(len(bb_XML_file_list))))+os.linesep)
            if count_rect>0:
                print "Ratio Images/Object_Rectangles: %.2f"%(float(count_img)/float(count_rect))
                summary.write(("Ratio Images/Object_Rectangles: %.2f"%(float(count_img)/float(count_rect)))+os.linesep)
def parse_XML_to_singleclass_txt(bb_XML_file_list, path_val_folder, path_dataset):

    with open('dataset/summary.txt', 'w') as summary:
        for class_name in CL.class_name_string_list:

            print "Starting making files for class:%s , May take a while.... "%class_name 

            progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()])
            path_bb_file=path_dataset+'/'+class_name+'/'+ class_name+string_bb_file
            path_class_code_file= path_dataset+'/'+class_name+'/'+class_name+string_class_code_file
            path_class_name_file= path_dataset+'/'+class_name+'/'+class_name+string_class_name_file
            path_chall_code_file= path_dataset+'/'+class_name+'/'+class_name+string_chall_code_file
            count_rect=0
            count_img=0
            for file_name in progress(bb_XML_file_list):
                with open(file_name, 'rt') as f:
                    tree = ElementTree.parse(f)
                    for obj in tree.findall('object'):
                        name = obj.find('name').text
                        class_code= name
                        name = vid_classes.code_to_class_string(name)

                        if name in ["nothing"]:
                            continue
                        else:

                            same_label=0
                            
                            image_single_class= Frame_Info()
                            image_single_class.dataset_path= path_val_folder
                            path_orig_file=path_val_folder

                            rectangle_single= Rectangle_Multiclass()
                            
                            #xmin x1 letf
                            #ymin y1 bottom
                            #xmax x2 right
                            #ymax y2 top
                        
                            for node in tree.iter():
                                tag=str(node.tag)
                    
                                if tag in ["folder"]:
                                    path_orig_file=path_orig_file+'/'+str(node.text)
                                    image_single_class.folder= str(node.text)
                                if tag in ["filename"]:
                                    image_single_class.filename=str(node.text)+'.PNG'
                                    path_orig_file=path_orig_file+'/'+str(node.text)+'.JPEG'

                                if tag in ["width"]:
                                    image_single_class.width= int(node.text)

                                if tag in ["height"]:
                                    image_single_class.height= int(node.text)

                                if tag in ["trackid"]:
                                    image_single_class.frame= int(os.path.basename(file_name).replace('.xml', ''))

                                if tag in ['name']:
                                    if str(vid_classes.code_to_class_string(str(node.text))) in ["nothing"]: 
                                        jump = 1
                                    if str(vid_classes.code_to_class_string(str(node.text))) is not class_name:
                                        jump = 1
                                    else : 
                                        jump=0
                                        rectangle_single.label_chall=int(vid_classes.class_string_to_comp_code(str(vid_classes.code_to_class_string(str(node.text)))))
                                        rectangle_single.label_code=str(node.text)
                                        rectangle_single.label=vid_classes.code_to_class_string(str(node.text))
                                if tag in ["xmax"]:
                                    if jump == 0:
                                        rectangle_single.x2=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),True))
                                if tag in ["xmin"]:
                                    if jump == 0:
                                        rectangle_single.x1=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),True))
                                if tag in ["ymin"]:
                                    if jump == 0:
                                        rectangle_single.y1=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),False))
                                if tag in ["ymax"]:
                                    if jump == 0:    
                                        rectangle_single.y2=float(utils_image.transform_point(image_single_class.width,image_single_class.height,width, height,float(node.text),False))
                                        image_single_class.append_rect(rectangle_single)
                                        count_rect=count_rect+1

                            if jump == 0:
                                
                                count_img=count_img+1
                                out_stream = open(path_bb_file, "a")
                                out_stream.write(image_single_class.get_info_string()+ os.linesep)
                                
                                out_stream = open(path_class_code_file, "a")
                                out_stream.write(image_single_class.get_rects_chall()+ os.linesep)
                                
                                out_stream = open(path_class_name_file, "a")
                                out_stream.write(image_single_class.get_rects_labels()+ os.linesep)
                                
                                out_stream = open(path_chall_code_file, "a")
                                out_stream.write(image_single_class.get_rects_code() + os.linesep)

                            break
            summary.write( ("Ended with Success Process for class:%s"%class_name )+os.linesep +"SUMMARY:" + os.linesep+ ("Parsed: %d BB Files"%len(bb_XML_file_list)) + os.linesep+ ("Added: %d Object Rectangles"%count_rect) + os.linesep+("Added: %d Images"%count_img)+os.linesep)
            print "Ended with Success Process for class:%s"%class_name 
            print "SUMMARY:"
            print "Parsed: %d BB Files"%len(bb_XML_file_list)
            print "Added: %d Object Rectangles"%count_rect
            print "Added: %d Images"%count_img
            if count_img>0: 
                print "Ratio BB_Files/Images: %.2f"%(float(count_img)/float(len(bb_XML_file_list)))
                summary.write(("Ratio BB_Files/Images: %.2f"%(float(count_img)/float(len(bb_XML_file_list))))+os.linesep)
            if count_rect>0:
                print "Ratio Images/Object_Rectangles: %.2f"%(float(count_img)/float(count_rect))
                summary.write(("Ratio Images/Object_Rectangles: %.2f"%(float(count_img)/float(count_rect)))+os.linesep)
def parse_XML_lightweight_txt(bb_XML_file_list, path_val_folder, path_dataset):

    count_rect = 0
    count_img = 0

    progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()])

    print "Start Processing & Building Dataset... may take a while..."

    path_mltcl_bb_file=path_dataset+'/'+string_mltcl_bb_file # Create this file in .dataset/airplane/airplane_bb_mltcl_file_list.txt
    path_mltcl_class_code_file=path_dataset+'/'+string_mltcl_class_code_file
    path_mltcl_class_name_file=path_dataset+'/'+string_mltcl_class_name_file
    path_mltcl_chall_code_file=path_dataset+'/'+string_mltcl_chall_code_file

    for file_name in progress(bb_XML_file_list):
        with open(file_name, 'rt') as f:
            tree = ElementTree.parse(f)
            for obj in tree.findall('object'):
                name = obj.find('name').text
                class_code= name
                name = vid_classes.code_to_class_string(name)

                if name in ["nothing"]:
                    continue
                else:
                    
                    same_label=0
                    #The files with the original data path are made in both: multiclass e single class
                    
                    
                    path_bb_file=path_dataset+'/'+name+'/'+ name+string_bb_file
                    path_class_code_file= path_dataset+'/'+name+'/'+name+string_class_code_file
                    path_class_name_file= path_dataset+'/'+name+'/'+name+string_class_name_file
                    path_chall_code_file= path_dataset+'/'+name+'/'+name+string_chall_code_file


                    path_orig_file=path_val_folder

                    
                    jump=0
                    
                    image_single_class= Frame_Info()
                    image_single_class.dataset_path= path_val_folder

                    image_multi_class= Frame_Info()
                    image_multi_class.dataset_path= path_val_folder


                    rectangle_single= Rectangle_Multiclass()
                    rectangle_multi= Rectangle_Multiclass()
                    
                    #xmin x1 letf
                    #ymin y1 bottom
                    #xmax x2 right
                    #ymax y2 top
                
                    for node in tree.iter():
                        tag=str(node.tag)
            
                        if tag in ["folder"]:
                            path_orig_file=path_orig_file+'/'+str(node.text)
                            image_single_class.folder= str(node.text)                            
                            image_multi_class.folder= str(node.text)

                        if tag in ["filename"]:
                            image_single_class.filename=str(node.text)+'.PNG'
                            image_multi_class.filename=str(node.text)+'.PNG'

                            path_orig_file=path_orig_file+'/'+str(node.text)+'.JPEG'

                        if tag in ['name']:
                            if str(vid_classes.code_to_class_string(str(node.text))) in ["nothing"]:
                                jump = 1
                            else : 
                                jump=0
                                rectangle_multi.label_chall=int(vid_classes.class_string_to_comp_code(str(vid_classes.code_to_class_string(str(node.text)))))
                                rectangle_multi.label_code=str(node.text)
                                rectangle_multi.label=vid_classes.code_to_class_string(str(node.text))

                                if str(node.text) == class_code: 
                                    same_label = 1
                                    rectangle_single.label_chall=int(vid_classes.class_string_to_comp_code(str(vid_classes.code_to_class_string(str(node.text)))))
                                    rectangle_single.label_code=str(node.text)
                                    rectangle_single.label=vid_classes.code_to_class_string(str(node.text))
                                else: same_label = 0
                                
                        if tag in ["xmax"]:
                            if jump == 0:
                                rectangle_multi.x2=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))
                                if same_label==1:
                                    rectangle_single.x2=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))
                        if tag in ["xmin"]:
                            if jump == 0:
                                rectangle_multi.x1=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))
                                if same_label==1:
                                    rectangle_single.x1=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))
                        if tag in ["ymax"]:
                            if jump == 0:
                                rectangle_multi.y2=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))                            
                                image_multi_class.append_rect(rectangle_multi) 
                                count_rect=count_rect+1
                                if same_label==1:
                                    rectangle_single.y2=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))
                                    image_single_class.append_rect(rectangle_single)
                        if tag in ["ymin"]:
                            if jump == 0:    
                                rectangle_multi.y1=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))
                                if same_label==1:
                                    rectangle_single.y1=float(utils_image.transform_point(image_multi_class.width,image_multi_class.height,width, height,float(node.text), False))

                    if jump == 0:
                        
                        count_img=count_img+1

                        out_stream = open(path_mltcl_bb_file, "a")
                        out_stream.write(image_multi_class.get_info_string()+ os.linesep)
                        
                        out_stream = open(path_mltcl_class_code_file, "a")
                        out_stream.write(image_multi_class.get_rects_code()+ os.linesep)
                        
                        out_stream = open(path_mltcl_class_name_file, "a")
                        out_stream.write(image_multi_class.get_rects_labels()+ os.linesep)
                        
                        out_stream = open(path_mltcl_chall_code_file, "a")
                        out_stream.write(image_multi_class.get_rects_chall() + os.linesep)

                        if same_label==1:
                            out_stream = open(path_bb_file, "a")
                            out_stream.write(image_single_class.get_info_string()+ os.linesep)
                            
                            out_stream = open(path_class_code_file, "a")
                            out_stream.write(image_single_class.get_rects_chall()+ os.linesep)
                            
                            out_stream = open(path_class_name_file, "a")
                            out_stream.write(image_single_class.get_rects_labels()+ os.linesep)
                            
                            out_stream = open(path_chall_code_file, "a")
                            out_stream.write(image_single_class.get_rects_code() + os.linesep)
                    break
    print "SUMMARY:"
    print "Parsed: %d BB Files"%len(bb_XML_file_list)
    print "Added: %d Object Rectangles"%count_rect
    print "Added: %d Images"%count_img
    if count_img>0: 
        print "Ratio BB_Files/Images: %.2f"%(float(count_img)/float(len(bb_XML_file_list)))
    if count_rect>0:
        print "Ratio Images/Object_Rectangles: %.2f"%(float(count_img)/float(count_rect))