bert icon indicating copy to clipboard operation
bert copied to clipboard

module 'tensorflow' has no attribute 'gfile'

Open kvaibhav2009 opened this issue 5 years ago • 11 comments

image

kvaibhav2009 avatar Jan 01 '20 11:01 kvaibhav2009

I tried using bert-tokenizer only for tokenization but cannot vouch for it . Further tried below.

image

kvaibhav2009 avatar Jan 01 '20 11:01 kvaibhav2009

You need to use tensorflow 1.11.0. TF syntax has changed for 2.0 which is why you're getting your errors.

adilapapaya avatar Jan 07 '20 04:01 adilapapaya

But the migration will be worthless as many things are deprecated in 2.0

On Tue, 7 Jan 2020, 09:57 adilapapaya, [email protected] wrote:

You need to use tensorflow 1.11.0. TF syntax has changed for 2.0 which is why you're getting your errors.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/google-research/bert/issues/977?email_source=notifications&email_token=AFIHA62FH3GBZHDOOAIPEFLQ4QAELA5CNFSM4KB2YJR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIHU2WY#issuecomment-571428187, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFIHA65NKJCU24NAKBTL46DQ4QAELANCNFSM4KB2YJRQ .

kvaibhav2009 avatar Jan 07 '20 12:01 kvaibhav2009

A quick monkey patch of tensorflow is a quick and ugly fix for this. Put the following line after you import tensorflow:

tf.gfile = tf.io.gfile

nobillygreen avatar Jan 29 '20 15:01 nobillygreen

@nobillygreen Thank you man for this hack

Akshaysharma29 avatar Apr 01 '21 09:04 Akshaysharma29

Gettting this new error: AttributeError: module 'tensorflow' has no attribute 'GraphDef'

A quick monkey patch of tensorflow is a quick and ugly fix for this. Put the following line after you import tensorflow:

tf.gfile = tf.io.gfile

manjunathsudheer666 avatar Apr 19 '21 14:04 manjunathsudheer666

@nobillygreen I tried it and i had another error: module 'tensorflow._api.v2.io.gfile' has no attribute 'MkDir'

dimaelzein avatar Jun 19 '21 10:06 dimaelzein

@nobillygreen same to me, I had another error Pre-training BERT from scratch with cloud TPU - Error TensorFlow has no attribute gfile

Ricco48 avatar Jul 06 '21 05:07 Ricco48

I get the same error even after changing it to .io. Any other suggestions? Reading people's comments elsewhere, I even tried importing 'tensorflow.compat.v1 as tf' instead of 'import tensorflow as tf'

126   #with tf.gfile.GFile(vocab_file, "r") as reader:
127   with tf.io.gfile.GFile(vocab_file, "r") as reader:

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

A quick monkey patch of tensorflow is a quick and ugly fix for this. Put the following line after you import tensorflow:

tf.gfile = tf.io.gfile

kritibhattarai23 avatar Oct 12 '21 15:10 kritibhattarai23

My Python version is 3.7.15 And tensorflow version is 2.9.2

I faced the same problem as @kb2009

The solution to change tf.gfile to tf.io.gfile

did not work until I added: tf.gfile = tf.io.gfile

Jagrutiti avatar Nov 12 '22 12:11 Jagrutiti

@nobillygreen I tried it and i had another error: module 'tensorflow._api.v2.io.gfile' has no attribute 'MkDir'

type makedir instead of MkDir

Fareed-Ahmad7 avatar Dec 04 '22 13:12 Fareed-Ahmad7