def make_dataset(root_path, annotation_path, subset): data = load_annotation_data(annotation_path) video_names, annotations = get_video_names_and_annotations(data, subset) class_to_idx = get_class_labels(data) idx_to_class = {} for name, label in class_to_idx.items(): idx_to_class[label] = name dataset = [] for i in range(len(video_names)): if i % 1000 == 0: print('dataset loading [{}/{}]'.format(i, len(video_names))) video_path = os.path.join(root_path, video_names[i]) if not os.path.exists(video_path): continue n_frames_file_path = os.path.join(video_path, 'number_Frames') n_frames = int(load_value_file(n_frames_file_path)) if n_frames <= 0: continue frame_indices_file_path = os.path.join(video_path, 'frames_name') frame_indices = load_list_file(frame_indices_file_path) sample = { 'video': video_path, 'n_frames': n_frames, 'frame_indices': frame_indices, 'video_id': video_names[i] } class_indexs = annotations[i]['label'] if not '-' in class_indexs: temp_label = np.zeros(len(class_to_idx)) temp_label[int(class_indexs)] = 1 #temp_label = int(class_indexs) #temp_map = np.zeros(len(class_to_idx)) #temp_map[int(class_indexs)] = 1 sample['label'] = temp_label #sample['map'] = temp_map else: temp = class_indexs.split('-') temp_label = np.zeros(len(class_to_idx)) for class_index in temp: temp_label[int(class_index)] = 1 #temp_label= int(temp[0]) #temp_map = np.zeros(len(class_to_idx)) #temp_map[int(temp[0])] = 1 sample['label'] = temp_label #sample['map'] = temp_map dataset.append(sample) return dataset
def make_dataset(root_path, annotation_path, subset): data = load_annotation_data(annotation_path) video_names, annotations = get_video_names_and_annotations(data, subset) class_to_idx = get_class_labels(data) idx_to_class = {} for name, label in class_to_idx.items(): idx_to_class[label] = name dataset = [] #test_file = open('/DATA/disk1/qzb/datasets/FCVID/test_files_' + subset + '.txt', 'w') for i in range(len(video_names)): if i % 1000 == 0: print('dataset loading [{}/{}]'.format(i, len(video_names))) video_path = os.path.join(root_path, video_names[i]) if not os.path.exists(video_path): continue n_frames_file_path = os.path.join(video_path, 'number_Frames') n_frames = int(load_value_file(n_frames_file_path)) if n_frames <= 0: continue frame_indices_file_path = os.path.join(video_path, 'frames_name') frame_indices = load_list_file(frame_indices_file_path) sample = { 'video': video_path, 'n_frames': n_frames, 'frame_indices': frame_indices, 'video_id': video_names[i] } #ipdb.set_trace() class_indexs = annotations[i]['label'] if not '-' in class_indexs: temp_label = np.zeros(len(class_to_idx)) temp_label[int(class_indexs)] = 1 sample['label'] = temp_label else: temp = class_indexs.split('-') temp_label = np.zeros(len(class_to_idx)) temp_label[int(temp[0])] = 1 #for class_index in temp: # temp_label[int(class_index)] = 1 sample['label'] = temp_label dataset.append(sample) #test_file.write(sample['video_id'] + ' ' + class_indexs + '\n') #test_file.close() return dataset