簡體   English   中英

ValueError:在乘法運算中使用占位符變量時不支持無值

[英]ValueError: None values not supported when using a placeholder variable in a multiplication operation

我在 tensorflow 的網絡圖中使用以下代碼:

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.

我的解決方案是在圖表外進行乘法運算,然后將此值提供給新的占位符:

 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)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM