def val_to_data(source): text_lines=[] frames_list=[] frame = None progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ',progressbar.Percentage(), ' ',progressbar.ETA()]) with open(source, 'r') as s: for line in s: id_frame, id_class, conf, xmin, ymin, xmax, ymax = line.strip().split(' ') text_lines.append((id_frame, id_class, conf, xmin, ymin, xmax, ymax)) for i in range(0, len(text_lines)): if frame is None: frame = fm.Frame_Info() frame.frame= text_lines[i][0] rect= multiclass_rectangle.Rectangle_Multiclass() # Not all the inserted values are really used rect.load_labeled_rect(0, text_lines[i][2], text_lines[i][2], text_lines[i][3], text_lines[i][4], text_lines[i][5], text_lines[i][6], text_lines[i][1], text_lines[i][1], text_lines[i][1]) frame.append_labeled_rect(rect) else : if frame.frame == text_lines[i][0]: rect= multiclass_rectangle.Rectangle_Multiclass() # Not all the inserted values are really used rect.load_labeled_rect(0, text_lines[i][2], text_lines[i][2], text_lines[i][3], text_lines[i][4], text_lines[i][5], text_lines[i][6], text_lines[i][1], text_lines[i][1], text_lines[i][1]) frame.append_labeled_rect(rect) else : frames_list.append(frame) frame = fm.Frame_Info() frame.frame= text_lines[i][0] rect= multiclass_rectangle.Rectangle_Multiclass() # Not all the inserted values are really used rect.load_labeled_rect(0, text_lines[i][2], text_lines[i][2], text_lines[i][3], text_lines[i][4], text_lines[i][5], text_lines[i][6], text_lines[i][1], text_lines[i][1], text_lines[i][1]) frame.append_labeled_rect(rect) frames_list.append(frame) return frames_list
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 get_multiclass_rectangles(H, confidences, boxes, rnn_len): boxes_r = np.reshape(boxes, (-1, H["grid_height"], H["grid_width"], rnn_len, 4)) confidences_r = np.reshape(confidences, (-1, H["grid_height"], H["grid_width"], rnn_len, H['num_classes'])) # print "boxes_r shape" + str(boxes_r.shape) # print "confidences" + str(confidences.shape) cell_pix_size = H['region_size'] all_rects = [[[] for _ in range(H["grid_width"])] for _ in range(H["grid_height"])] for n in range(rnn_len): for y in range(H["grid_height"]): for x in range(H["grid_width"]): bbox = boxes_r[0, y, x, n, :] abs_cx = int(bbox[0]) + cell_pix_size/2 + cell_pix_size * x abs_cy = int(bbox[1]) + cell_pix_size/2 + cell_pix_size * y w = bbox[2] h = bbox[3] # conf = np.max(confidences_r[0, y, x, n, 1:]) index, conf = get_silhouette_confidence(confidences_r[0, y, x, n, 1:]) # print index, conf # print np.max(confidences_r[0, y, x, n, 1:]) # print "conf" + str(conf) # print "conf" + str(confidences_r[0, y, x, n, 1:]) new_rect=multiclass_rectangle.Rectangle_Multiclass() new_rect.set_unlabeled_rect(abs_cx,abs_cy,w,h,conf) all_rects[y][x].append(new_rect) # print "confidences_r" + str(confidences_r.shape) all_rects_r = [r for row in all_rects for cell in row for r in cell] min_conf = get_higher_confidence(all_rects_r) acc_rects=[rect for rect in all_rects_r if rect.true_confidence>min_conf] rects = [] for rect in all_rects_r: if rect.true_confidence>min_conf: r = al.AnnoRect() r.x1 = rect.cx - rect.width/2. r.x2 = rect.cx + rect.width/2. r.y1 = rect.cy - rect.height/2. r.y2 = rect.cy + rect.height/2. r.score = rect.true_confidence r.silhouetteID=rect.label rects.append(r) print len(rects),len(acc_rects) return rects, acc_rects