'tensorflow' 没有属性 'config'

Moi*_*han 7 python machine-learning tensorflow

我正在尝试运行以下行:

print("Num GPUs Available: " , len(tensorflow.config.experimental.list_physical_devices('GPU')))
Run Code Online (Sandbox Code Playgroud)

但它返回错误:

AttributeError: module 'tensorflow' has no attribute 'config'
Run Code Online (Sandbox Code Playgroud)

任何想法我做错了什么?

编辑:这是初始化代码

from __future__ import absolute_import, division, print_function, unicode_literals

import os
from glob import glob
import time
import tensorflow
#os.environ['KERAS_BACKEND'] = 'tensorflow'
#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # 3 = INFO, WARNING, and ERROR messages are not printed

from tqdm import tqdm
from keras.utils import np_utils
import numpy as np
import pandas as pd
from IPython.display import FileLink
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
import seaborn as sns 
from IPython.display import display, Image
import matplotlib.image as mpimg
import cv2

from sklearn.model_selection import train_test_split
from sklearn.datasets import load_files       
from sklearn.utils import shuffle
from sklearn.metrics import log_loss

from keras.applications.vgg16 import VGG16

from keras.models import Sequential, Model
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, BatchNormalization, GlobalAveragePooling2D, Input
from keras.preprocessing.image import ImageDataGenerator
from keras.preprocessing import image
from keras.callbacks import ModelCheckpoint, EarlyStopping


import tflearn
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
from tensorflow.keras import datasets, layers, models
Run Code Online (Sandbox Code Playgroud)

我也在使用 Tensorflow 2.0。如果有人可以提供帮助,那就太好了

小智 5

对于 Tensorflow 2.x,您应该使用tf.test.gpu_device_name()

import tensorflow as tf
print("Num of GPUs available: ", len(tf.test.gpu_device_name()))
Num of GPUs available:  13
Run Code Online (Sandbox Code Playgroud)

  • AttributeError:模块“tensorflow”没有属性“test” (10认同)
  • 相同的错误 - “AttributeError:模块‘tensorflow’没有属性‘test’” (2认同)

小智 1

可能是因为您安装了tensorflow 2.0,但代码是为tensorflow 1.0编写的

AttributeError:模块“tensorflow”没有属性“ConfigProto”

请尝试一下这个方法,看看是否有效。