コード例 #1
0
ファイル: tvec.py プロジェクト: trungnt13/odin-ai
# training PLDA
Z3_train, y_train = make_dnn_prediction(f_z3, X=train, title="TRAIN")
print("Z3_train:", Z3_train.shape, y_train.shape)
Z3_valid, y_valid = make_dnn_prediction(f_z3, X=valid, title="VALID")
print("Z3_valid:", Z3_valid.shape, y_valid.shape)
plda = PLDA(n_phi=200,
            random_state=K.get_rng().randint(10e8),
            n_iter=12,
            labels=labels,
            verbose=0)
plda.fit(np.concatenate([Z3_train, Z3_valid], axis=0),
         np.concatenate([y_train, y_valid], axis=0))
y_pred_log_proba = plda.predict_log_proba(Z3_test)
evaluate(y_true=X_test_true,
         y_pred_log_proba=y_pred_log_proba,
         labels=labels,
         title="Test set (PLDA - Latent prediction)",
         path=os.path.join(EXP_DIR, 'test_latent.pdf'))
# ====== visualize ====== #
visualize_latent_space(X_org=X_test_data,
                       X_latent=Z1_test,
                       name=X_test_name,
                       labels=X_test_true,
                       title="latent1")
visualize_latent_space(X_org=X_test_data,
                       X_latent=Z2_test,
                       name=X_test_name,
                       labels=X_test_true,
                       title="latent2")
V.plot_save(os.path.join(EXP_DIR, 'latent.pdf'))
コード例 #2
0
ファイル: tvec.py プロジェクト: imito/odin
# ===========================================================================
y_pred_proba, Z1_test, Z2_test, Z3_test = make_dnn_prediction(
    functions=[f_pred_proba, f_z1, f_z2, f_z3], X=X_test_data, title='TEST')
print("Test Latent:", Z1_test.shape, Z2_test.shape, Z3_test.shape)
y_pred = np.argmax(y_pred_proba, axis=-1)
evaluate(y_true=X_test_true, y_pred_proba=y_pred_proba, labels=labels,
         title="Test set (Deep prediction)",
         path=os.path.join(EXP_DIR, 'test_deep.pdf'))
# ====== make a streamline classifier ====== #
# training PLDA
Z3_train, y_train = make_dnn_prediction(f_z3, X=train, title="TRAIN")
print("Z3_train:", Z3_train.shape, y_train.shape)
Z3_valid, y_valid = make_dnn_prediction(f_z3, X=valid, title="VALID")
print("Z3_valid:", Z3_valid.shape, y_valid.shape)
plda = PLDA(n_phi=200, random_state=K.get_rng().randint(10e8),
            n_iter=12, labels=labels, verbose=0)
plda.fit(np.concatenate([Z3_train, Z3_valid], axis=0),
         np.concatenate([y_train, y_valid], axis=0))
y_pred_log_proba = plda.predict_log_proba(Z3_test)
evaluate(y_true=X_test_true, y_pred_log_proba=y_pred_log_proba, labels=labels,
         title="Test set (PLDA - Latent prediction)",
         path=os.path.join(EXP_DIR, 'test_latent.pdf'))
# ====== visualize ====== #
visualize_latent_space(X_org=X_test_data, X_latent=Z1_test,
                       name=X_test_name, labels=X_test_true,
                       title="latent1")
visualize_latent_space(X_org=X_test_data, X_latent=Z2_test,
                       name=X_test_name, labels=X_test_true,
                       title="latent2")
V.plot_save(os.path.join(EXP_DIR, 'latent.pdf'))
コード例 #3
0
    adj_norm_batch, adj_orig_batch, adj_idx = get_consecutive_batch(
        0, args.batch_size, adj, adj_norm)
    features = features_batch
    feed_dict = construct_feed_dict(adj_norm_batch, adj_orig_batch, features,
                                    placeholders)
    feed_dict.update({placeholders['dropout']: args.dropout})
    outs = sess.run([model.reconstructions], feed_dict=feed_dict)

    reconstructions = outs[0].reshape([args.batch_size, 180, 180])

    #     Visualize sample full matrix of original, normalized, and reconstructed batches.
    for i in range(adj_orig_batch.shape[0]):
        visualize_matrix(adj_orig_batch, i, model_name, 'original_' + str(i))
        visualize_matrix(adj_norm_batch, i, model_name, 'normalized_' + str(i))
        visualize_matrix(reconstructions, i, model_name,
                         'reconstruction_' + str(i))

    adj_norm_batch, adj_orig_batch, adj_idx = get_random_batch(
        args.batch_size, adj, adj_norm)
    features = features_batch
    feed_dict = construct_feed_dict(adj_norm_batch, adj_orig_batch, features,
                                    placeholders)
    feed_dict.update({placeholders['dropout']: args.dropout})
    outs = sess.run([model.z_mean], feed_dict=feed_dict)

    z = outs[0]

    # Visualize Latent Space
    onehot = np.array([0 if idx < 203 else 1 for idx in adj_idx])
    visualize_latent_space(z, onehot, model_name)
コード例 #4
0
    feed_dict.update({placeholders['dropout']: args.dropout})
    outs = sess.run([model.reconstructions, model.z_mean], feed_dict=feed_dict)

    reconstructions = outs[0].reshape([args.batch_size, 180, 180])
    z_mean = outs[1]
    #     Visualize sample full matrix of original, normalized, and reconstructed batches.
    for i in range(adj_orig_batch.shape[0]):
        visualize_matrix(adj_orig_batch, i, model_name, 'original_' + str(i))
        visualize_matrix(adj_norm_batch, i, model_name, 'normalized_' + str(i))
        visualize_matrix(reconstructions, i, model_name,
                         'reconstruction_' + str(i))

    idx_all, z_all = [], []
    for i in range(10):
        adj_norm_batch, adj_orig_batch, adj_idx = get_random_batch(
            args.batch_size, adj, adj_norm)
        features = features_batch
        feed_dict = construct_feed_dict(adj_norm_batch, adj_orig_batch,
                                        features, placeholders)
        feed_dict.update({placeholders['dropout']: args.dropout})
        outs = sess.run([model.reconstructions, model.z_mean],
                        feed_dict=feed_dict)
        idx_all.append(adj_idx)
        z_all.append(outs[1])

#     Visualize Latent Space
    z = np.array(z_all).reshape(-1, 10)
    idx = np.array(idx_all).flatten()
    onehot = np.array([0 if i < 203 else 1 for i in idx_all[0]])
    visualize_latent_space(z_all[0], onehot, model_name)