11
我試圖使用:train = optimizer.minimize(loss)
,但標準優化器不適用於tf.float64
。因此我想將我的loss
從tf.float64
截斷爲僅tf.float32
。TensorFlow:將float64張量施加到float32
Traceback (most recent call last):
File "q4.py", line 85, in <module>
train = optimizer.minimize(loss)
File "/Library/Python/2.7/site-packages/tensorflow/python/training/optimizer.py", line 190, in minimize
colocate_gradients_with_ops=colocate_gradients_with_ops)
File "/Library/Python/2.7/site-packages/tensorflow/python/training/optimizer.py", line 229, in compute_gradients
self._assert_valid_dtypes([loss])
File "/Library/Python/2.7/site-packages/tensorflow/python/training/optimizer.py", line 354, in _assert_valid_dtypes
dtype, t.name, [v for v in valid_dtypes]))
ValueError: Invalid type tf.float64 for Add_1:0, expected: [tf.float32].
所以你想從float64轉換成float32嗎? –
是的。作爲一個臨時解決方案,我將浮點數組從float64移動到了float32,這是我的float64張量來自哪裏並且解決了我的問題,但是必須有一種在tf本身中進行轉換的方法 –