tensorflow_core._api.v2.config 中缺少实验列表设备属性

Posted

技术标签:

【中文标题】tensorflow_core._api.v2.config 中缺少实验列表设备属性【英文标题】:experimental_list_devices attribute missing in tensorflow_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' 

我该如何解决这个错误?

【问题讨论】:

【参考方案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

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

【讨论】:

以上是关于tensorflow_core._api.v2.config 中缺少实验列表设备属性的主要内容,如果未能解决你的问题,请参考以下文章

module 'tensorflow_core._api.v2.config' has no attribute 'experimental_list_devices'

未找到 Tensorflow_core 估计器

ModuleNotFoundError:没有名为“tensorflow_core.estimator”的模块用于 tensorflow 2.1.0

AttributeError:模块“tensorflow_core.keras.layers.experimental.preprocessing”没有属性“RandomFlip”

ModuleNotFoundError: No module named 'tensorflow_core.keras'

没有模块'命名为 tensorflow_core.esitmator'。