TensorFlow Dynamic Variables

I need to create a matrix in TensorFlow in order to save some values. The trick is that the matrix must maintain a dynamic shape.

I try to do the same as in numpy:

myVar = tf.Variable(tf.zeros((x,y), validate_shape=False) 

where x=(?) and y=2 . But this does not work, because zeros do not support the "partially known TensorShape", so how do I do this in TensorFlow?

+6
source share
3 answers

1) You can use tf.fill(dims, value=0.0) , which works with dynamic forms.

2) You can use a placeholder for a variable dimension, for example, for example:

 m = tf.placeholder(tf.int32, shape=[]) x = tf.zeros(shape=[m]) with tf.Session() as sess: print(sess.run(x, feed_dict={m: 5})) 
+1
source

If you know the form of the session, this may help.

 import tensorflow as tf import numpy as np v = tf.Variable([], validate_shape=False) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) print(sess.run(v, feed_dict={v: np.zeros((3,4))})) print(sess.run(v, feed_dict={v: np.zeros((2,2))})) 
0
source

I just found a solution for tf.Variables with an unknown shape at the time of plotting, and I answered the most recent of these questions. Take a look here .

0
source

Source: https://habr.com/ru/post/1266434/


All Articles