【问题标题】:experimental_list_devices attribute missing in tensorflow_core._api.v2.configtensorflow_core._api.v2.config 中缺少实验列表设备属性
【发布时间】:2020-06-20 05:29:21
【问题描述】:

我在 Windows 10 上使用 tensorflow 2.1。正在运行

model.add(Conv3D(16, (22, 5, 5), strides=(1, 2, 2), padding='valid',activation='relu',data_format= "channels_first", input_shape=input_shape))

在 spyder 上,我收到此错误:

{ AttributeError: module 'tensorflow_core._api.v2.config' has no attribute 'experimental_list_devices' }

我该如何解决这个错误?

【问题讨论】:

    标签: python tensorflow keras spyder


    【解决方案1】:

    我在这里找到了答案 - https://github.com/keras-team/keras/issues/13684。 我对来自 Anaconda 下的 keras 的 load_model() 有同样的问题:

    AttributeError: 模块 'tensorflow_core._api.v2.config' 没有属性 'experimental_list_devices'

    我在

    中找到了问题的根源

    ...\anaconda3\envs\tf_env\Lib\site-packages\keras\backend\tensorflow_backend.py

    在第 506 行我更改了行

    _LOCAL_DEVICES = tf.config.experimental_list_devices()
    

    devices = tf.config.list_logical_devices()
    
    _LOCAL_DEVICES = [x.name for x in devices]
    

    它有效

    【讨论】:

      【解决方案2】:

      对于 jupyter 用户,你可以使用这个:-

      import tensorflow as tf
      import keras.backend.tensorflow_backend as tfback
      
      print("tf.__version__ is", tf.__version__)
      print("tf.keras.__version__ is:", tf.keras.__version__)
      
      def _get_available_gpus():
          """Get a list of available gpu devices (formatted as strings).
      
          # Returns
              A list of available GPU devices.
          """
          #global _LOCAL_DEVICES
          if tfback._LOCAL_DEVICES is None:
              devices = tf.config.list_logical_devices()
              tfback._LOCAL_DEVICES = [x.name for x in devices]
          return [x for x in tfback._LOCAL_DEVICES if 'device:gpu' in x.lower()]
      
      tfback._get_available_gpus = _get_available_gpus
      

      【讨论】:

        【解决方案3】:

        我遇到了类似的问题。 就我而言,我的代码是这样的:

        from keras import load_model
        

        看来 keras 有问题。所以我改用了这个。

        from tensorflow.keras.models import load_model
        

        解决了我的问题,希望对你有帮助。

        【讨论】:

          猜你喜欢
          • 2020-04-03
          • 2020-07-04
          • 1970-01-01
          • 2020-07-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多