Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'tensorflow' has no attribute 'config'

I am trying to run the following line:

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

But it returns the error:

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

Any ideas what I'm doing wrong?

Edit: Here's the initialization code

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

I am using Tensorflow 2.0 as well. If anyone could help that would be great

like image 925
Moiz Khan Avatar asked Feb 02 '20 00:02

Moiz Khan


2 Answers

For Tensorflow 2.x you should be using 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
like image 137
freeagh Avatar answered Nov 11 '22 12:11

freeagh


It could be because you have installed tensorflow 2.0 but the code was written for tensorflow 1.0

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

Please try this and see if it works.

like image 37
Knl_Kolhe Avatar answered Nov 11 '22 13:11

Knl_Kolhe