Enter a specific value for variable in tensorflow

Use assign () to assign a specific value after initializing Variable of tensorflow. For example, after reading the variable value from checkpoint, only a part can be rewritten with numpy.array.

assign_test.py


import tensorflow as tf
import numpy as np

x = tf.Variable(tf.zeros([5]))
y = tf.Variable(tf.ones([5]))

sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())

print 'x original = ', x.eval()

input_placeholder = tf.placeholder(tf.float32, shape=[5])

assign_op = x.assign(input_placeholder)
sess.run(assign_op, feed_dict={input_placeholder: np.ones(5).astype(np.float32)})

print 'x <- numpy array ...', x.eval()

assign_op = x.assign(y)
sess.run(assign_op)

print 'x <- another variable ...', x.eval()

Recommended Posts

Enter a specific value for variable in tensorflow
Save a specific variable in tensorflow.session
Count specific strings in a file
Change the list in a for statement
Get a token for conoha in python
tensorflow does not enter in windows + anaconda.
How to embed a variable in a python string
A proposal for versioning of features in Kedro
Clone with a specific branch / tag in GitPython
Zero padding for dynamic variable values in Python
Extract lines containing a specific "string" in Pandas
Tips for using ElasticSearch in a good way
How to count numbers in a specific range
Isn't there a default value in the dictionary?
Get a row containing a specific element in np.where
[Python] No value for argument'self' in unbound method call
Specific sample code for working with SQLite3 in Python
Register a task in cron for the first time
Try searching for a million character profile in Python
What's in that variable (when running a Python script)
Convenient to use matplotlib subplots in a for statement
How to build a development environment for TensorFlow (1.0.0) (Mac)
When you want to plt.save in a for statement
[Linux] How to put your IP in a variable
Set a proxy for Python pip (described in pip.ini)
Stop an instance with a specific tag in Boto3
Get the value of a specific key up to the specified index in the dictionary list in Python