mod = RegionEncoder(n_nodes=n_nodes, n_nodal_features=n_nodal_features, h_dim_graph=h_dim_graph, h_dim_img=h_dim_img, lambda_ae=lambda_ae, lambda_edge=lambda_edge, lambda_g=lambda_g, neg_samples_gcn=neg_samples_gcn, h_dim_size=h_dim_size, img_dims=img_dims, lambda_weight_decay=lambda_weight_decay) mod.run_train_job(region_grid, epochs=epochs, lr=learning_rate, tol_order=3) if torch.cuda.is_available(): embedding = mod.embedding.data.cpu().numpy() else: embedding = mod.embedding.data.numpy() fname = "{}embedding-iter-{}.txt".format(OUT_DIR, i) write_embeddings(arr=embedding, n_nodes=n_nodes, fname=fname) with open(OUT_DIR + "params-{}.txt".format(i), 'w') as f: param = params[i] f.write("{}: ".format(i)) for p in param: f.write("{:.4f}, ".format(p)) f.write("\n")
epochs = int(sys.argv[1]) learning_rate = float(sys.argv[2]) else: epochs = 25 learning_rate = .1 context_gcn = 4 neg_samples_gcn = 10 c = get_config() region_grid = RegionGrid(config=c) region_grid.load_weighted_mtx() n_nodes = len(region_grid.regions) h_dim_size = int(c['hidden_dim_size']) n_nodal_features = region_grid.feature_matrix.shape[1] gcn = GCN(n_features=n_nodal_features, h_dim_size=h_dim_size) embedding = gcn.run_train_job(region_grid, n_epoch=epochs, learning_rate=learning_rate, penalty=(1, 1), n_neg_samples=context_gcn, n_pos_samples=neg_samples_gcn) if torch.cuda.is_available(): embedding = embedding.data.cpu().numpy() else: embedding = embedding.data.numpy() embed_fname = '{}gcn_all_embedding.txt'.format(c['data_dir_main']) write_embeddings(arr=embedding, n_nodes=region_grid.n_regions, fname=embed_fname)
if __name__ == "__main__": import numpy as np from grid.create_grid import RegionGrid if len(sys.argv) > 1: epochs = int(sys.argv[1]) learning_rate = float(sys.argv[2]) batch_size = int(sys.argv[3]) else: epochs = 25 learning_rate = .05 batch_size = 25 c = get_config() region_grid = RegionGrid(config=c) region_grid.load_img_data(std_img=True) img_tensor = torch.Tensor(region_grid.img_tensor) h_dim_size = int(c['hidden_dim_size']) auto_encoder = AutoEncoder(img_dims=(50, 50), h_dim_size=h_dim_size) embedding = auto_encoder.run_train_job(n_epoch=epochs, img_tensor=img_tensor, lr=learning_rate) if torch.cuda.is_available(): embedding = embedding.data.cpu().numpy() else: embedding = embedding.data.numpy() write_embeddings(arr=embedding, n_nodes=region_grid.n_regions, fname=c['tile2vec_file'])
h_dim_graph = 64 h_dim_img = 64 h_dim_size = int(c['hidden_dim_size']) lambda_ae = .5 lambda_edge = .1 lambda_g = .1 neg_samples_gcn = 10 epochs = 15 learning_rate = .1 if len(sys.argv) > 1: epochs = int(sys.argv[1]) learning_rate = float(sys.argv[2]) mod = RegionEncoder(n_nodes=n_nodes, n_nodal_features=n_nodal_features, h_dim_graph=h_dim_graph, h_dim_img=h_dim_img, lambda_ae=lambda_ae, lambda_edge=lambda_edge, lambda_g=lambda_g, neg_samples_gcn=neg_samples_gcn, h_dim_size=h_dim_size) mod.run_train_job(region_grid, epochs=epochs, lr=learning_rate, tol_order=3) if torch.cuda.is_available(): embedding = mod.embedding.data.cpu().numpy() else: embedding = mod.embedding.data.numpy() write_embeddings(arr=embedding, n_nodes=n_nodes, fname=c['embedding_file']) mod.plt_learning_curve("plots/region-learning-curve.pdf", plt_all=False, log_scale=True)
if len(sys.argv) > 1: epochs = int(sys.argv[1]) learning_rate = float(sys.argv[2]) batch_size = int(sys.argv[3]) else: epochs = 25 learning_rate = .1 batch_size = 20 c = get_config() region_grid = RegionGrid(config=c) region_grid.load_img_data(std_img=True) img_tensor = torch.Tensor(region_grid.img_tensor) h_dim_size = int(c['hidden_dim_size']) auto_encoder = AutoEncoder(img_dims=(50, 50), h_dim_size=h_dim_size) embedding = auto_encoder.run_train_job(n_epoch=epochs, batch_size=batch_size, img_tensor=img_tensor, lr=learning_rate) if torch.cuda.is_available(): embedding = embedding.data.cpu().numpy() else: embedding = embedding.data.numpy() write_embeddings(arr=embedding, n_nodes=region_grid.n_regions, fname=c['autoencoder_embedding_file'])
import sys sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from config import get_config from grid.create_grid import RegionGrid from model.utils import write_embeddings c = get_config() region_grid = RegionGrid(config=c) region_grid.load_img_data(std_img=True) region_grid.load_img_data() h_dim_size = int(c['hidden_dim_size']) img_dims = region_grid.img_tensor.shape n_samples = img_dims[0] n_channel = img_dims[1] n_rows = img_dims[2] n_cols = img_dims[3] flat_shape = n_channel*n_rows*n_cols X = region_grid.img_tensor.reshape((n_samples, flat_shape)) pca_model = PCA(n_components=h_dim_size) embedding = pca_model.fit_transform(X) write_embeddings(embedding, n_nodes=n_samples, fname=c['pca_file'])