def compute_responses(mlps_dir): stim_type = 'breakfast' spatial_downsample_factor = 4 if stim_type == 'breakfast': video_dir = './temp/breakfast_sorted/cam01/' features_dir = os.path.join( './temp/video_features/', os.path.basename(os.path.normpath(mlps_dir))) else: raise NotImplementedError print 'Reading in the videos from %s...' % mlps_dir videos = read_videos(video_dir, spatial_downsample_factor=spatial_downsample_factor) print 'Read.' action_names = os.listdir(video_dir) print 'Classes : ', action_names for i in range(11): print 'Using MLP %d...' % i with open(os.path.join(mlps_dir, 'mlp_%d' % i), 'rb') as f: Wh, bh, Wo, bo = pickle.load(f) mlp = create_mlp_from_params(Wh, bh, Wo, bo, rectify=True) print 'MLP created from saved parameters. Computing MLP output...' sim_rsps = [[transform(mlp, video) for video in class_videos] for class_videos in videos] print 'Storing MLP output on %s videos...' % stim_type mlp_output_dir = os.path.join(features_dir, 'mlp_%d' % i) dump_features(mlp_output_dir, sim_rsps, action_names) print 'Stored.\n'
def compute_responses(mlps_dir): stim_type = 'breakfast' spatial_downsample_factor = 4 if stim_type == 'breakfast': video_dir = './temp/breakfast_sorted/cam01/' features_dir = os.path.join('./temp/video_features/', os.path.basename( os.path.normpath(mlps_dir))) else: raise NotImplementedError print 'Reading in the videos from %s...' % mlps_dir videos = read_videos(video_dir, spatial_downsample_factor=spatial_downsample_factor) print 'Read.' action_names = os.listdir(video_dir) print 'Classes : ', action_names for i in range(11): print 'Using MLP %d...' % i with open(os.path.join(mlps_dir, 'mlp_%d' % i), 'rb') as f: Wh, bh, Wo, bo = pickle.load(f) mlp = create_mlp_from_params(Wh, bh, Wo, bo, rectify=True) print 'MLP created from saved parameters. Computing MLP output...' sim_rsps = [[transform(mlp, video) for video in class_videos] for class_videos in videos] print 'Storing MLP output on %s videos...' % stim_type mlp_output_dir = os.path.join(features_dir, 'mlp_%d' % i) dump_features(mlp_output_dir, sim_rsps, action_names) print 'Stored.\n'
def get_simulated_responses(model_dir, videos): responses = [] for i in range(11): with open(os.path.join(model_dir, 'mlp_%d' % i), 'rb') as f: Wh, bh, Wo, bo = pickle.load(f) mlp = create_mlp_from_params(Wh, bh, Wo, bo, rectify=True) sim_rsps = [[transform(mlp, video) for video in class_videos] for class_videos in videos] responses.append(sim_rsps) return responses
def get_v1_nns(model_dir): """ nns = [fann.neural_net() for i in range(11)] paths = ['./output/nets/%d.net' % i for i in range(11)] for i, p in enumerate(paths): nns[i].create_from_file(p) """ nns = [] for i in range(11): with open(os.path.join(model_dir, 'mlp_%d' % i), 'rb') as f: Wh, bh, Wo, bo = pickle.load(f) nns.append(create_mlp_from_params(Wh, bh, Wo, bo, rectify=True)) return nns