我该如何解决?

时间:2019-09-26 11:03:01

标签: python tensorflow gpu

我不知道这是什么问题。安装TensorFlow-GPU 2.0之后,我只是检查TensorFlow是否正常工作。并解决此类问题。

import tensorflow as tf
if tf.test.is_gpu_available():
    with tf.device("/gpu:0"):
        tf_string_array = tf.constant(["TensorFlow", "Deep Learning", "AI"])
    tf_string_array.device

执行我的代码后。我收到此错误:

RuntimeError:无法将类型为字符串的Tensor复制到设备/ job:localhost /副本:0 / task:0 / device:GPU:0。

enter image description here

我正在安装tensorflow来关注此博客: enter link description here

1 个答案:

答案 0 :(得分:0)

使用以下步骤验证tensorflow-GPU的正确安装

  • 您可以检查tensorflow是否使用GPU

    class SmoelenBoek : ApplicationFragment(){ var profiles: Array<Profile> = arrayOf() override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_smoelenboek, null) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) SharedInstance.api.getAllUsers { profiles = it smoelenboekRecyclerView.layoutManager = LinearLayoutManager(context) smoelenboekRecyclerView.adapter = SmoelenBoekAdapter(profiles) } } }

  • 要查明使用哪个设备,可以启用日志设备放置 像这样:

    import tensorflow as tf print(tf.test.is_gpu_available())

  • 您可以尝试将计算分配给gpu,看看是否有错误

    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))