【问题标题】:Error while Tensorflow import using the command 'from tensorflow.keras.models import Sequential'使用命令 \'from tensorflow.keras.models import Sequential\' 导入 Tensorflow 时出错
【发布时间】:2022-12-24 01:07:57
【问题描述】:

无法导入名称 'pywrap_dtensor_device' 来自 'tensorflow.python' (C:\python3\lib\site-packages\tensorflow\python_在里面.py

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    很容易有很多可能的方式,其中之一就是包含急切模式和非急切模式。

    您可以为作业指定设备,因为具有基本配置的 Tensorflow 2.8 不需要 jobid *

    他们管理日程安排,或者您可以使用经理。

    [渴望模式]:

    device_spec = DeviceSpec(device_type="GPU", device_index=0)
    print( device_spec )
    print( device_spec.to_string() )
    with tf.device(device_spec.to_string()):
        my_var = tf.Variable(1.)
        squared_var = tf.square(my_var)
        print( squared_var )
    

    [无渴望模式]:

    tf.compat.v1.disable_eager_execution()
    device_spec = DeviceSpec(job="1234", device_type="GPU", device_index=0)
    print( device_spec )
    print( device_spec.to_string() )
    with tf.device(device_spec.to_string()):
        my_var = tf.Variable(1.)
        squared_var = tf.square(my_var)
        print( squared_var )
    

    [ 输出 ]:

    <tensorflow.python.framework.device_spec.DeviceSpecV2 object at 0x000001AB1149EBE0>
    /job:1234/device:GPU:0
    Tensor("Square:0", shape=(), dtype=float32, device=/job:1234/device:GPU:0)
    

    【讨论】:

    • 这是大多数人在更改版本时失败的不同之处。
    • 这是您误解的另一个问题,您实际上没有回答。
    • 感谢您的回复。不幸的是它没有用。
    • 您需要指定更多信息,但一个原因是 Tensorflow 升级的版本可能不适用于旧版本。
    猜你喜欢
    • 2020-09-30
    • 2015-10-19
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-03
    相关资源
    最近更新 更多