本文主要是介绍tf.linspace时出现Could not find valid device for node.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
背景:
在使用tensorflow2.x的时候,当使用tf.linspace的时候会出现如下的报错:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'import tensorflow as tf
from tensorflow import keras
import numpy as npdef out():# x = tf.constant(np.arange(12).reshape(2,6))x = tf.linspace(-6 , 6, 12)print(x)target = tf.sigmoid(x)print(target)def __test_out__():out()if __name__ == '__main__':__test_out__()
解决方案:
查看官方文档:
https://www.tensorflow.org/api_docs/python/tf/linspacehttps://www.tensorflow.org/api_docs/python/tf/linspace
上面说的很清楚,start、stop必须是float类型的,
因此,代码修改如下:
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'import tensorflow as tf
from tensorflow import keras
import numpy as npdef out():# x = tf.constant(np.arange(12).reshape(2,6))x = tf.linspace(-6. , 6., 12)print(x)target = tf.sigmoid(x)print(target)def __test_out__():out()if __name__ == '__main__':__test_out__()
正常运行!!!
这篇关于tf.linspace时出现Could not find valid device for node.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!