【问题标题】:'tensorflow' has no attribute 'config'“张量流”没有属性“配置”
【发布时间】:2020-02-02 00:03:51
【问题描述】:

我正在尝试运行以下行:

print("Num GPUs Available: " , len(tensorflow.config.experimental.list_physical_devices('GPU')))

但它返回错误:

AttributeError: module 'tensorflow' has no attribute 'config'

任何想法我做错了什么?

编辑: 这是初始化代码

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

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

【问题讨论】:

  • 你能发布你的张量流初始化代码吗?

标签: python tensorflow machine-learning


【解决方案1】:

对于 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

【讨论】:

    【解决方案2】:

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

    AttributeError: module 'tensorflow' has no attribute 'ConfigProto'

    请尝试一下,看看它是否有效。

    【讨论】:

    • 现在我得到错误 AttributeError: '_FieldProperty' object has no attribute 'list_physical_devices'
    • @MoizKhan 您可以尝试使用 tensorflow 1.14 或 1.13 运行相同的代码,并使用 pip install tensorflow==1.14
    猜你喜欢
    • 1970-01-01
    • 2020-06-15
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 2018-09-25
    • 2020-01-04
    • 2017-12-25
    • 2021-05-24
    相关资源
    最近更新 更多