I want to use the value of the tensorflow weight for research.

Asked 1 years ago, Updated 1 years ago, 33 views

What should I do if I am doing CNN on tensorflow and I want to get an array of weights?
Is there a method?I don't think I can do it normally...

For example, get an array of weights
w1 = Get array of weights (tf.variable...)
print (w1)

I would like to write a source similar to .

tensorflow

2022-09-30 17:11

2 Answers

The This slide will help you with print debugging for tensorflow.

Specifically, you can get the output by specifying the session.run argument with a tensor of weight W.

mnist=input_data.read_data_sets (FLAGS.data_dir, one_hot=True)
 x = tf.placeholder (tf.float32, [None,784])
 W=tf.Variable(tf.zeros([784,10]))
 b=tf.Variable(tf.zeros([10]))
 y = tf.matmul(x,W)+b

 cross_entropy=tf.reduce_mean(
     tf.nn.softmax_cross_entropy_with_logits(labels=y_,logits=y))
 train_step=tf.train.GradientDescentOptimizer (0.5).minimize(cross_entropy)

 sess=tf.InteractiveSession()
 tf.global_variables_initializer().run()
 # Train
 display_step=1
 for i in range (1000):
     batch_xs, batch_ys =mnist.train.next_batch(100)
     # Specify the weight tensor for sess.run
     w_out,_=sess.run([W,train_step],feed_dict={x:batch_xs,y_:batch_ys})
     # Output weight
     if i%display_step==0:
         print(w_out)

I hope it will be helpful.


2022-09-30 17:11

It may have already been resolved.

v1=tf.Variable([1,2,3,4])
sess=tf.Session()
w1 = sess.run(v1)

Can't you get Variable like this?


2022-09-30 17:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.