def main(confs): classification_types = ['verb', 'noun'] results_fpaths = adict() classes_maps = adict() for c in classification_types: for test_set in confs[c].challenge_test_sets: results_fpaths[test_set.name][ c] = './{}/audio_{}_testset_{}_{}_lr_{}_model_{:03d}.csv'.format( confs[c].checkpoint, confs[c].type, test_set.name, confs[c].arc, confs[c].lr, confs[c].test_epoch) classes_maps[c] = pickle.load(open(confs[c].classes_map, "rb")) submission_results = to_submission_struct(results_fpaths, classes_maps) seen_json_fpath = 'seen_verb_{}_{}_{}_noun_{}_{}_{}.json'.format( confs['verb'].arc, confs['verb'].lr, confs['verb'].test_epoch, confs['noun'].arc, confs['noun'].lr, confs['noun'].test_epoch) with open(seen_json_fpath, 'w') as outfile: json.dump(submission_results['s1'], outfile) unseen_json_fpath = 'seen_verb_{}_{}_{}_noun_{}_{}_{}.json'.format( confs['verb'].arc, confs['verb'].lr, confs['verb'].test_epoch, confs['noun'].arc, confs['noun'].lr, confs['noun'].test_epoch) with open(unseen_json_fpath, 'w') as outfile: json.dump(submission_results['s2'], outfile)
def main(modalities_confs, weights, classes_map): verbs_by_action, nouns_by_action = build_categories_indices(classes_map) modalities = list(modalities_confs.keys()) test_sets = ['s1', 's2'] results_fpaths = adict() for m in modalities: conf = modalities_confs[m].conf for t in test_sets: if m == 'audio': results_fpaths[t][ m] = '{}/{}_{}_testset_{}_{}_lr_{}_model_{:03d}.npz'.format( conf.checkpoint, conf.snapshot_pref, conf.type, t, conf.arc, conf.lr, conf.test_epoch) else: results_fpaths[t][ m] = '{}/tsn_{}_{}_testset_{}_{}_lr_{}_model_{:03d}.npz'.format( conf.checkpoint, conf.snapshot_pref, m, t, conf.arch, conf.lr, conf.test_model) submission_results = to_submission_struct(modalities, results_fpaths, verbs_by_action, nouns_by_action, weights) seen_json_fpath = 'seen_action_weighted_{}.json'.format( '+'.join(modalities)) with open(seen_json_fpath, 'w') as outfile: json.dump(submission_results['s1'], outfile) unseen_json_fpath = 'unseen_action_weighted_{}.json'.format( '+'.join(modalities)) with open(unseen_json_fpath, 'w') as outfile: json.dump(submission_results['s2'], outfile)
def loadConfigs(self): configs = loadObject(self.config_file) model_configs = configs[0] self.input_mean = model_configs["input_mean"] self.input_dim = tuple(model_configs["input_dim"]) self.net_type = model_configs["net_type"] archi_configs = configs[1:] self.layers = [] self.configs = {} for layer_config in archi_configs: name = layer_config[0] self.layers.append(name) self.configs[name] = adict(layer_config[1])
def main(conf): classes_map = pickle.load(open(conf.classes_map, "rb")) verbs_by_action, nouns_by_action = build_categories_indices(classes_map) results_fpaths = adict() for t in ['s1', 's2']: results_fpaths[ t] = './{}/{}_{}_testset_{}_lr_{}_model_{:03d}.npz'.format( conf.checkpoint, conf.snapshot_pref, conf.type, t, conf.lr, conf.test_epoch) submission_results = to_submission_struct(results_fpaths, verbs_by_action, nouns_by_action) seen_json_fpath = 'seen_fusion_action.json' with open(seen_json_fpath, 'w') as outfile: json.dump(submission_results['s1'], outfile, sort_keys=True) unseen_json_fpath = 'unseen_fusion_action.json' with open(unseen_json_fpath, 'w') as outfile: json.dump(submission_results['s2'], outfile, sort_keys=True)
def main(confs, classes_maps): test_sets = ['s1', 's2'] classification_types = ['verb', 'noun'] results_fpaths = adict() for c in classification_types: conf = confs[c] for t in test_sets: results_fpaths[t][ c] = './{}/{}_{}_testset_{}_lr_{}_model_{:03d}.npz'.format( conf.checkpoint, conf.snapshot_pref, conf.type, t, conf.lr, conf.test_epoch) submission_results = to_submission_struct(results_fpaths, classes_maps) seen_json_fpath = 'seen_fusion_verb+noun.json' with open(seen_json_fpath, 'w') as outfile: json.dump(submission_results['s1'], outfile) unseen_json_fpath = 'unseen_fusion_verb+noun.json' with open(unseen_json_fpath, 'w') as outfile: json.dump(submission_results['s2'], outfile)
for t in ['s1', 's2']: results_fpaths[ t] = './{}/{}_{}_testset_{}_lr_{}_model_{:03d}.npz'.format( conf.checkpoint, conf.snapshot_pref, conf.type, t, conf.lr, conf.test_epoch) submission_results = to_submission_struct(results_fpaths, verbs_by_action, nouns_by_action) seen_json_fpath = 'seen_fusion_action.json' with open(seen_json_fpath, 'w') as outfile: json.dump(submission_results['s1'], outfile, sort_keys=True) unseen_json_fpath = 'unseen_fusion_action.json' with open(unseen_json_fpath, 'w') as outfile: json.dump(submission_results['s2'], outfile, sort_keys=True) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('conf', type=lambda p: str(Path(p).absolute()), help='JSON configuration filepath') json_conf = parser.parse_args().conf with open(json_conf) as json_file: conf = adict(json.load(json_file)) if conf.type != 'action': raise Exception('Action configuration file is not action type') main(conf)
unseen_json_fpath = 'unseen_action_weighted_{}.json'.format( '+'.join(modalities)) with open(unseen_json_fpath, 'w') as outfile: json.dump(submission_results['s2'], outfile) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('weighted_conf', type=lambda p: str(Path(p).absolute()), help='Weighted JSON configuration filepath') weighted_json_conf = parser.parse_args().weighted_conf with open(weighted_json_conf) as json_file: weighted_json = adict(json.load(json_file)) modalities_confs = adict() modalities = list(weighted_json.modalities.keys()) for m in modalities: with open(weighted_json.modalities[m].conf) as json_file: modalities_confs[m].conf = adict(json.load(json_file)) if m != 'audio': if modalities_confs[m].conf.class_type != 'action': raise Exception( 'Action configuration file is not action type') elif modalities_confs[m].conf.type != 'action': raise Exception('Action configuration file is not action type') classes_map = pickle.load(open(weighted_json.classes_map, "rb")) main(modalities_confs, weighted_json.weights, classes_map)
def main(args): segments = pickle.load(open(args.segments, "rb")) hdf5_fpath = os.path.join(args.audio_dir, args.hdf5_fname) hdf5_file = tables.open_file(hdf5_fpath, mode='w') spectrograms = hdf5_file.create_earray(hdf5_file.root, 'spectrograms', tables.Float64Atom(), shape=(0, 331, 62 * args.num_secs), filters=tables.Filters(complevel=0)) if args.is_test: table_segments = hdf5_file.create_table('/', 'segments', TestActionSegment, "Test action segments") else: table_segments = hdf5_file.create_table('/', 'segments', ActionSegment, "Action segments labels") if args.stats_json: with open(args.stats_json) as json_file: stats = adict(json.load(json_file)) std_min = (stats.min - stats.mean) / stats.std_dev std_max = (stats.max - stats.mean) / stats.std_dev elif args.std_stats_json: with open(args.std_stats_json) as json_file: stats = adict(json.load(json_file)) elif args.norm_stats_json: with open(args.norm_stats_json) as json_file: stats = adict(json.load(json_file)) start_idx = 0 segment = table_segments.row for index, row in segments.iterrows(): action_fpath = get_audio_fpath(args.audio_dir, index, row, args.is_test) s = audio.extract_spectrogram(action_fpath, 0.03, 0.015, 661) if args.stats_json: # Standardization s = (s - stats.mean) / stats.std_dev # Normalization s = (s - std_min) / (std_max - std_min) elif args.std_stats_json: # Standardization s = (s - stats.mean) / stats.std_dev elif args.norm_stats_json: # Normalization s = (s - stats.min) / (stats.max - stats.min) frames, last_idx = audio.to_frames(s, 62 * args.num_secs) for frame in frames: spectrograms.append(frame[None]) if not args.is_test: segment['narration'] = row.narration segment['verb_class'] = row.verb_class segment['noun_class'] = row.noun_class segment['participant_id'] = row.participant_id segment['video_id'] = row.video_id segment['num_frames'] = len(frames) segment['start_idx'] = start_idx end_idx = start_idx + len(frames) segment['end_idx'] = end_idx segment['last_frame_idx'] = last_idx segment['spectrogram_mean'] = s.mean() segment['spectrogram_max'] = s.max() segment['spectrogram_min'] = s.min() segment['spectrogram_size'] = s.size segment['duration'] = get_duration(row) segment['index'] = index segment.append() start_idx = end_idx table_segments.flush() hdf5_file.close()
participant_id = getattr(annotation, PARTICIPANT_ID_COL) start_timestamp = getattr(annotation, START_TS_COL) stop_timestamp = getattr(annotation, STOP_TS_COL) start_seconds = IO.timestamp_to_seconds(start_timestamp) stop_seconds = IO.timestamp_to_seconds(stop_timestamp) duration = IO.seconds_to_timestamp(stop_seconds - start_seconds) csv_writer.writerow([ participant_id, video_id, segment_fname, start_timestamp, stop_timestamp, duration ]) annotations_dir = pathlib.Path('annotations').absolute() input_fpaths = adict() input_fpaths.verbs = annotations_dir.joinpath('EPIC_verb_classes.csv') input_fpaths.nouns = annotations_dir.joinpath('EPIC_noun_classes.csv') input_fpaths.train_labels = annotations_dir.joinpath( 'EPIC_train_action_labels.pkl') input_fpaths.s1_test = annotations_dir.joinpath('EPIC_test_s1_timestamps.pkl') input_fpaths.s2_test = annotations_dir.joinpath('EPIC_test_s2_timestamps.pkl') all_train_labels = pickle.load(open(input_fpaths.train_labels.as_posix(), 'rb')) to_csv(all_train_labels, 'annotations/all_action_segments.csv') filtered_train_labels = IO.filter_action_classes(input_fpaths.verbs, input_fpaths.nouns, input_fpaths.train_labels)[2] to_csv(filtered_train_labels, 'annotations/action_segments.csv')
parser = argparse.ArgumentParser( description=HELP, formatter_class=argparse.RawTextHelpFormatter, ) parser.add_argument('annotations_dir', type=lambda p: pathlib.Path(p).absolute(), help='Path to annotations directory') parser.add_argument('--type', type=str, dest='classification_type', default='action', help='Classification type') args = parser.parse_args() annotations_dir = args.annotations_dir input_fpaths = adict() input_fpaths.verbs = annotations_dir.joinpath('EPIC_verb_classes.csv') input_fpaths.nouns = annotations_dir.joinpath('EPIC_noun_classes.csv') input_fpaths.train_labels = annotations_dir.joinpath( 'EPIC_train_action_labels.pkl') output_fpaths = adict() if args.classification_type == 'all_actions': output_fpaths.verbs = annotations_dir.joinpath( 'EPIC_ARC_all_verbs.pkl') output_fpaths.nouns = annotations_dir.joinpath( 'EPIC_ARC_all_nouns.pkl') output_fpaths.train_labels = annotations_dir.joinpath( 'EPIC_ARC_all_train_labels.pkl') output_fpaths.splits = annotations_dir.joinpath( 'EPIC_ARC_all_splits.pkl')
json.dump(submission_results['s1'], outfile) unseen_json_fpath = 'unseen_fusion_verb+noun.json' with open(unseen_json_fpath, 'w') as outfile: json.dump(submission_results['s2'], outfile) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('conf', type=lambda p: str(Path(p).absolute()), help='JSON configuration filepath') json_conf = parser.parse_args().conf with open(json_conf) as json_file: test_json = adict(json.load(json_file)) confs = adict() with open(test_json.confs.verb_conf) as json_file: confs.verb = adict(json.load(json_file)) if confs.verb.type != 'verb': raise Exception('Verb configuration file is not verb type') with open(test_json.confs.noun_conf) as json_file: confs.noun = adict(json.load(json_file)) if confs.noun.type != 'noun': raise Exception('Noun configuration file is not noun type') classes_maps = adict() classes_maps['verb'] = pickle.load(open(test_json.classes_maps.verb, "rb")) classes_maps['noun'] = pickle.load(open(test_json.classes_maps.noun, "rb"))
json.dump(submission_results['s2'], outfile) if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('noun_conf', type=lambda p: str(Path(p).absolute()), help='Noun JSON configuration filepath') parser.add_argument('verb_conf', type=lambda p: str(Path(p).absolute()), help='Verb JSON configuration filepath') noun_json_conf = parser.parse_args().noun_conf verb_json_conf = parser.parse_args().verb_conf with open(noun_json_conf) as json_file: noun_conf = adict(json.load(json_file)) with open(verb_json_conf) as json_file: verb_conf = adict(json.load(json_file)) if verb_conf.type != 'verb': raise Exception('Verb configuration file is not verb type') if noun_conf.type != 'noun': raise Exception('Noun configuration file is not noun type') confs = adict() confs.verb = verb_conf confs.noun = noun_conf main(confs)
Marco ''' PASCAL = 'PASCAL' COCO = 'COCO' IMAGENET = 'IMAGENET' ''' Config for program parameters ''' CONFIG = adict() CONFIG.DATA.STATISTICS = True # dissection CONFIG.DIS.DATASETS = [PASCAL, COCO] CONFIG.DIS.MODEL = "VGG16" # the model to be dissected CONFIG.DIS.IOU_THRESHOLD = 0.1 CONFIG.DIS.TOP = 3 CONFIG.DIS.QUANTILE = 50 CONFIG.DIS.ANNO_PIXEL_THRESHOLD = 0 CONFIG.DIS.REPORT_TEXT = True CONFIG.DIS.REPORT_FIGURE = False