0

我在张量流的网络图中使用以下代码:

self.num_quantiles = tf.placeholder(dtype=tf.int32)

num_samples = self.rnn.get_shape().as_list()[0]
quantiles_shape = [self.num_quantiles * num_samples, 1]
self.quantiles = tf.random_uniform(quantiles_shape, minval=0, maxval=1, dtype=tf.float32)

但是,由于乘法“不支持无值”,我得到一个错误。

谁能告诉我如何使用我的占位符正确执行乘法?

  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  <ipython-input-31-4f68d3e68617> in <module>
  2 tf.reset_default_graph()
  3 #We define the primary and target q-networks
  ----> 4 mainQN = Qnetwork('main')
  5 targetQN = Qnetwork('target')
  6 

<ipython-input-27-5b3a3af3cf09> in __init__(self, myScope)
136         #batch_size = state_net.get_shape().as_list()[0]
137         num_samples = self.rnn.get_shape().as_list()[0] #batch_size
--> 138         quantiles_shape = [self.num_quantiles * num_samples, 1]
139         self.quantiles = tf.random_uniform(quantiles_shape, minval=0, maxval=1, dtype=tf.float32)
140 

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\ops\math_ops.py in binary_op_wrapper(x, y)
813       elif not isinstance(y, sparse_tensor.SparseTensor):
814         try:
--> 815           y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
816         except TypeError:
817           # If the RHS is not a tensor, it might be a tensor aware object

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\ops.py in  convert_to_tensor(value, dtype, name, preferred_dtype)
1037     ValueError: If the `value` is a tensor not of given `dtype` in graph mode.
1038   """
-> 1039   return convert_to_tensor_v2(value, dtype, preferred_dtype, name)
1040 
1041 

C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape, allow_broadcast)
452   else:
453     if values is None:
--> 454       raise ValueError("None values not supported.")
455     # if dtype is provided, forces numpy array to be the type
456     # provided if possible.

ValueError: None values not supported.
4

1 回答 1

0

我的解决方案是在图表外进行乘法运算,然后将此值提供给新的占位符:

 self.quantiles_shape=tf.placeholder(dtype=tf.int32)
 num_samples = self.rnn.get_shape().as_list()[0]
 self.quantiles = tf.random_uniform([self.quantiles_shape, 1], minval=0, maxval=1, dtype=tf.float32)

这不是我想要的理想,但至少它有效。

于 2019-10-27T02:23:05.333 回答