예제 #1
0
파일: new.py 프로젝트: tjacek/sim_nn
 def __call__(self, in_path, out_path, n_epochs, cat_i):
     frames = imgs.read_seqs(in_path)
     train, test = data.split_dict(frames)
     X, y = data.to_seq_dataset(train)
     X, y = self.gen(X, y, cat_i)
     n_channels = X[0].shape[-1]
     params = {"input_shape": (X[0].shape[1], X[0].shape[2], n_channels)}
     sim_metric, model = sim.build_siamese(params, self.make_model)
     sim_metric.fit(X, y, epochs=n_epochs, batch_size=100)
     if (out_path):
         model.save(out_path)
예제 #2
0
def make_model(in_path, out_path, n_epochs=5):
    seq_dict = single.read_frame_feats(in_path)
    train, test = data.split_dict(seq_dict)
    X, y = get_data(train)
    params = {
        'n_cats': y.shape[1],
        'ts_len': X.shape[1],
        'n_feats': X.shape[2]
    }
    model = clf_model(params)
    model.fit(X, y, epochs=n_epochs, batch_size=64)
    model.save(out_path)
예제 #3
0
def make_sim_template(in_path, out_path, n_epochs, gen_pairs):
    frames = imgs.read_seqs(in_path)
    train, test = data.split_dict(frames)
    X, y = data.to_seq_dataset(train)
    X, y = gen_pairs(X, y)
    #    X,y=gen.binary_data(X,y,cat_i,n_samples)
    n_channels = X[0].shape[-1]
    params = {"input_shape": (X[0].shape[1], X[0].shape[2], n_channels)}
    sim_metric, model = sim.build_siamese(params, make_five)
    sim_metric.fit(X, y, epochs=n_epochs, batch_size=100)
    if (out_path):
        model.save(out_path)
예제 #4
0
파일: __init__.py 프로젝트: tjacek/sim_nn
def train_model(in_path, out_path, n_epochs=5, cat_i=0):
    frames = imgs.read_seqs(in_path)
    train, test = data.split_dict(frames)
    X, y = data.to_frame_dataset(train)
    X = np.array(X)
    if (type(cat_i) == int):
        y = [int(y_i == cat_i) for y_i in y]
    y = keras.utils.to_categorical(y)
    n_cats = 2 if (type(cat_i) == int) else y.shape[-1]
    n_channels = X[0].shape[-1]
    model = make_model(n_cats, n_channels)
    model.fit(X, y, epochs=n_epochs, batch_size=32)
    if (out_path):
        model.save(out_path)
예제 #5
0
파일: vae.py 프로젝트: tjacek/sim_nn
def make_model(in_path, out_path=None, n_epochs=1000, recon=True):
    frames = imgs.read_seqs(in_path)
    train, test = data.split_dict(frames)
    X, y = data.to_frame_dataset(train)
    X = np.array(X)
    #    add_noise(X)
    params = {'n_channels': X.shape[-1]}
    model = make_autoencoder(params)

    original_dim = 64 * 64

    model.summary()
    model.fit(X, epochs=n_epochs, batch_size=64)
    model.save(out_path)
예제 #6
0
def pretrain_clf(nn_path, seq_path, clf_path, n_epochs=1000):
    reg_model = load_model(nn_path)
    dims = reg_model.get_input_at(0).shape
    params = {'ts_len': int(dims[1]), 'n_feats': int(dims[2]), 'n_cats': 20}
    clf_model = basic.ts.clf_model(params)

    for i in range(7):
        print(i)
        weigts_i = reg_model.layers[i].get_weights()
        clf_model.layers[i].set_weights(weigts_i)

    seq_dict = single.read_frame_feats(seq_path)
    train, test = data.split_dict(seq_dict)
    X, y = basic.ts.get_data(train)
    clf_model.fit(X, y, epochs=n_epochs, batch_size=64)
    clf_model.save(clf_path)
예제 #7
0
파일: ae.py 프로젝트: tjacek/sim_nn
def make_model(frames, out_path=None, n_epochs=1000, recon=True):
    if (type(frames) == str):
        frames = imgs.read_seqs(frames)
    train, test = data.split_dict(frames)
    X, y = data.to_frame_dataset(train)
    X = sub_sample(X)
    X = np.array(X)
    #    add_noise(X)
    params = {
        'n_channels': X.shape[-1],
        "dim": (X.shape[1], X.shape[2]),
        'scale': (4, 4)
    }
    model, auto = make_autoencoder(params)
    model.summary()
    model.fit(X, X, epochs=n_epochs, batch_size=16)
    auto.save(out_path)
    if (recon):
        model.save(out_path + "_recon")
예제 #8
0
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)