experimental_list_devices tensorflow_core._api 中缺少属性。v2.config
experimental_list_devices attribute missing in tensorflow_core._api.v2.config
我在 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' }
如何解决这个错误?
我在这里找到了答案 - https://github.com/keras-team/keras/issues/13684。
我在 Anaconda 下的 keras load_model()
遇到了同样的问题:
AttributeError: module 'tensorflow_core._api.v2.config' has no attribute '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]
而且有效
对于 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
我遇到了类似的问题。
就我而言,我的代码是这样的:
from keras import load_model
keras好像有问题。所以我用这个代替。
from tensorflow.keras.models import load_model
解决了我的问题,希望对你有帮助。
我在 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' }
如何解决这个错误?
我在这里找到了答案 - https://github.com/keras-team/keras/issues/13684。
我在 Anaconda 下的 keras load_model()
遇到了同样的问题:
AttributeError: module 'tensorflow_core._api.v2.config' has no attribute '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]
而且有效
对于 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
我遇到了类似的问题。 就我而言,我的代码是这样的:
from keras import load_model
keras好像有问题。所以我用这个代替。
from tensorflow.keras.models import load_model
解决了我的问题,希望对你有帮助。