Add files via upload

Modified train.py
This commit is contained in:
HarshitGupta11 2019-06-02 18:27:26 +05:30 committed by GitHub
parent cc0ccd4a11
commit 32529df3a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,9 +3,9 @@ import numpy as np
from model import create_model
def train(train_synteny_matrices,train_branch_length_species,train_branch_length_homology_species,train_mean_gene_length,train_dist_p_s,train_dist_p_hs,train_distance,train_labels):
def train(train_synteny_matrices_global,train_synteny_matrices_local,train_branch_length_species,train_branch_length_homology_species,train_mean_gene_length,train_dist_p_s,train_dist_p_hs,train_distance,train_labels):
graph,saver=create_model()
synm,bls,blhs,gl,dps,dphs,dis,lr,y=graph.get_collection("input_nodes")
synmg,synml,bls,blhs,gl,dps,dphs,dis,lr,y=graph.get_collection("input_nodes")
loss,t_op,accuracy,init=graph.get_collection("output_nodes")
with tf.Session(graph=graph) as sess:
sess.run(init)
@ -15,7 +15,8 @@ def train(train_synteny_matrices,train_branch_length_species,train_branch_length
for j in range(num_epochs):
for i in range(50000//batch_size):
feed_dict={
synm:train_synteny_matrices[i*batch_size:(i+1)*batch_size],
synmg:train_synteny_matrices_global[i*batch_size:(i+1)*batch_size],
synml:train_synteny_matrices_local[i*batch_size:(i+1)*batch_size],
bls:train_branch_length_species[i*batch_size:(i+1)*batch_size],
blhs:train_branch_length_homology_species[i*batch_size:(i+1)*batch_size],
gl:train_mean_gene_length[i*batch_size:(i+1)*batch_size].reshape((batch_size,1)),
@ -27,21 +28,9 @@ def train(train_synteny_matrices,train_branch_length_species,train_branch_length
}
sess.run(t_op,feed_dict=feed_dict)
feed_dict={
synm:train_synteny_matrices[i*batch_size:(i+1)*batch_size].transpose((0,2,1,3)),
blhs:train_branch_length_species[i*batch_size:(i+1)*batch_size],
bls:train_branch_length_homology_species[i*batch_size:(i+1)*batch_size],
gl:train_mean_gene_length[i*batch_size:(i+1)*batch_size].reshape((batch_size,1)),
dphs:train_dist_p_s[i*batch_size:(i+1)*batch_size].reshape((batch_size,1)),
dps:train_dist_p_hs[i*batch_size:(i+1)*batch_size].reshape((batch_size,1)),
dis:train_distance[i*batch_size:(i+1)*batch_size].reshape((batch_size,1)),
lr:learn,
y:train_labels[i*batch_size:(i+1)*batch_size]
}
sess.run(t_op,feed_dict=feed_dict)
test_dict={
synm:train_synteny_matrices[-15000:],
synmg:train_synteny_matrices_global[-15000:],
synml:train_synteny_matrices_local[-15000:],
bls:train_branch_length_species[-15000:],
blhs:train_branch_length_homology_species[-15000:],
gl:train_mean_gene_length[-15000:].reshape((15000,1)),
@ -49,19 +38,8 @@ def train(train_synteny_matrices,train_branch_length_species,train_branch_length
dphs:train_dist_p_hs[-15000:].reshape((15000,1)),
dis:train_distance[-15000:].reshape((15000,1)),
y:train_labels[-15000:]
}
train_dict={
synm:train_synteny_matrices[:15000],
bls:train_branch_length_species[:15000],
blhs:train_branch_length_homology_species[:15000],
gl:train_mean_gene_length[:15000].reshape((15000,1)),
dps:train_dist_p_s[:15000].reshape((15000,1)),
dphs:train_dist_p_hs[:15000].reshape((15000,1)),
dis:train_distance[:15000].reshape((15000,1)),
y:train_labels[:15000]
}
accuracy_train,loss_train=sess.run([accuracy,loss],feed_dict=train_dict)
}
accuracy_test,loss_test=sess.run([accuracy,loss],feed_dict=test_dict)
print("Epoch:{} Train Accuracy:{} Train Loss:{} Test Accuracy:{} Test Loss:{}".format(j+1,accuracy_train*100,loss_train,accuracy_test*100,loss_test))
print("Epoch:{} Test Accuracy:{} Test Loss:{}".format(j+1,accuracy_test*100,loss_test))
learn*=0.97
saver.save(sess,"saved_models/model.ckpt")