import tensorflow as tf import numpy as np import tensorboard
fofdata = open('data.txt','r') xof1 = [] for line in fofdata.readlines(): line = line.split('\n') for a in line[0].split('\t'): xof1.append(float(a)) fofdata.close()
xof1 = np.array(xof1) xof1 = xof1.reshape(-1,5)
fofresult = open('result.txt','r') yof1 = [] for line in fofresult.readlines(): line = line.split('\n') for a in line[0].split('\t'): yof1.append(float(a)) fofresult.close()
yof1 = np.array(yof1) yof1 = yof1.reshape(-1,1)
with tf.name_scope('inputsoft'): xoft = tf.placeholder(tf.float32,[None,5]) yoft = tf.placeholder(tf.float32,[None,1]) defadd_layer(name,x,sizeofin,sizeofout,activation_function=None): nameoflayer = "layer_{}".format(name) with tf.name_scope(nameoflayer): with tf.name_scope("weights"): Weights = tf.Variable(tf.truncated_normal([sizeofin,sizeofout]),name="W") tf.summary.histogram(nameoflayer+"/weights",Weights) with tf.name_scope("bias"): biases = tf.Variable(tf.random_normal([1,sizeofout]),name="b") with tf.name_scope("Wx_add_b"): Wx_add_b = tf.add(tf.matmul(x,Weights),biases) if activation_function isNone: outputs = Wx_add_b else : outputs = activation_function(Wx_add_b,) tf.summary.histogram(nameoflayer+"/outputs",outputs) return outputs
for i in range(1000): sessoft.run(trainoft,feed_dict={xoft: xof1,yoft: yof1}) if i % 20 == 0: result = sessoft.run(mergedoft,feed_dict={xoft: xof1,yoft: yof1}) writeroft.add_summary(result, i) if1 < i < 100: print(sessoft.run(lossoft,feed_dict={xoft:xof1,yoft:yof1})) elif i % 50 == 0: print(sessoft.run(lossoft,feed_dict={xoft:xof1,yoft:yof1}))