def proj_template(in_path,out_path,proj_funcs): files.make_dir(out_path) paths=files.top_files(in_path) for seq_path_i in paths: print(seq_path_i) seq_i=imgs.read_frames(seq_path_i,as_dict=False) proj_seq_i=[proj_i(seq_i) for proj_i in proj_funcs] new_imgs=np.concatenate(proj_seq_i,axis=1) out_i="%s/%s" % (out_path,seq_path_i.split("/")[-1]) imgs.save_frames(out_i,new_imgs)
def extract(model_path, out_path, frame_path, img_type="binary"): action_frames = imgs.read_frames(frame_path, True, img_type) model = load_model(model_path) extractor = Model(inputs=model.input, outputs=model.get_layer("hidden").output) X = action_format(action_frames) # raise Exception(X.shape) X_feats = model.predict(X) names = list(action_frames.keys()) feat_dict = {names[i]: feat_i for i, feat_i in enumerate(X_feats)} single.save_ts_feats(feat_dict, out_path)
def make_model(in_path, out_path, n_epochs=5, i=None, nn_type="basic", img_type="binary"): action_frames = imgs.read_frames(in_path, True, img_type) # raise Exception(list(action_frames.values())[0].shape) train, test = data.split_dict(action_frames) assert (equal_dims(train)) X = action_format(train) y = np.array( [int(name_i.split("_")[0]) - 1 for name_i in list(train.keys())]) dims = X.shape params = {"input_shape": (dims[1], dims[2], dims[3])} if (nn_type == "sim"): model = sim_model(X, y, i, params, n_epochs) else: model = basic_model(X, y, i, params, n_epochs) if (out_path): model.save(out_path)
def action_read(in_path): return imgs.read_frames(in_path,True)
def action_shape(in_path): frames = imgs.read_frames(in_path) for frame_i in frames: print(frame_i.shape)