profile
viewpoint

Ask questionsAttributeError: module 'tensorflow' has no attribute 'gfile'

Hi,

I am trying to load a file using the following code below. However, whenever I run my code I get an error stating that AttributeError: module 'tensorflow' has no attribute 'gfile' . I have successfully installed gin using pip install gin-config.

import tensorflow as tf

def load_directory_data(directory):
  data = {}
  data["sentence"] = []
  data["sentiment"] = []
  for file_path in os.listdir(directory):
    with tf.io.gfile.GFile(os.path.join(directory, file_path), "r") as f:
      data["sentence"].append(f.read())
      data["sentiment"].append(re.match("\d+_(\d+)\.txt", file_path).group(1))
  return pd.DataFrame.from_dict(data)

I've even done import gin.tf , but when I run my code I then get...

` File "C:\Users\WTC\Anaconda3\lib\site-packages\bert\tokenization.py", line 125, in load_vocab with tf.gfile.GFile(vocab_file, "r") as reader:

AttributeError: module 'tensorflow' has no attribute 'gfile'`

Any thoughts as to why?

tensorflow/tensorflow

Answer questions Gurubux

Tensor-flow Version - 2.0.0-alpha0

Same error occurred while running a notebook from the Tensorflow site - Build a linear model with Estimators <br> Download the dataset:

from official.wide_deep import census_dataset
from official.wide_deep import census_main

census_dataset.download("/tmp/census_data/")

AttributeError Traceback (most recent call last) <ipython-input-9-fa1d43ace000> in <module>() 2 from official.wide_deep import census_main 3 ----> 4 census_dataset.download("/tmp/census_data/")

/content/models/official/wide_deep/census_dataset.py in download(data_dir) 76 def download(data_dir): 77 """Download census data if it is not already present.""" ---> 78 tf.gfile.MakeDirs(data_dir) 79 80 training_file_path = os.path.join(data_dir, TRAINING_FILE)

AttributeError: module 'tensorflow' has no attribute 'gfile' <hr>

The document suggests the following changes in the file.

Should I go about making the following changes manually in the file census_dataset.py ?

WARNING: Logging before flag parsing goes to stderr. W0625 16:04:36.412110 139807458662144 deprecation_wrapper.py:119] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/census_dataset.py:78: The name tf.gfile.MakeDirs is deprecated. Please use tf.io.gfile.makedirs instead.

W0625 16:04:36.413802 139807458662144 deprecation_wrapper.py:119] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/census_dataset.py:81: The name tf.gfile.Exists is deprecated. Please use tf.io.gfile.exists instead.

W0625 16:04:38.253764 139807458662144 deprecation_wrapper.py:119] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/census_dataset.py:62: The name tf.gfile.Open is deprecated. Please use tf.io.gfile.GFile instead.

W0625 16:04:38.488776 139807458662144 deprecation_wrapper.py:119] From /tmpfs/src/temp/site/en/tutorials/estimators/models/official/wide_deep/census_dataset.py:73: The name tf.gfile.Remove is deprecated. Please use tf.io.gfile.remove instead.

#https://github.com/google/gin-config/issues/9 #https://github.com/tobegit3hub/simple_tensorflow_serving/issues/45

useful!
source:https://uonfu.com/
answerer
Gurubux Gurubux India https://gurubux.wordpress.com/ Computer Engineer B.E | Software Developer | Machine Learning Aspirant
Github User Rank List