Can someone please help, why am I getting this error AttributeError: module 'tensorflow' has no attribute 'version' ? ver installed TF2.0.0.rc0
from __future__ import absolute_import, division, print_function, unicode_literals
# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras
# Helper libraries
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
print(tf.version)
You need to modify your last statement as print(tf.__version__) instead of print(tf.version) as the attribute name is __version__ rather than version. There are two leading and trailing underscores.
Related
I am following a tutorial to convert keras (.hdf5/.h5) model to onnx model. the link is (https://www.youtube.com/watch?v=7ndUGBzGVvg)
So, the code is
import tensorflow as tf
from tensorflow.keras.models import load_model
print(tf.__version__)
model = load_model('./model/weights.28-3.73.hdf5')
model.summary()
import tf2onnx
I also tried importing import keras2onnx but it generates error saying
module 'tensorflow.python.keras' has no attribute 'applications'. So I tried with tf2onnx.
I am using
keras==2.4.3
tensorflow==2.5.0
python==3.8.5
tf2onnx==1.13.0
onnx==1.13.0
I need to use the smartwatch_gestures from Tensorflow datasets and here is my code:
pip install --upgrade tfds-nightly
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
train_data,ds_info = tfds.load('smartwatch_gestures', as_supervised=True, split = 'train')
print(ds_info.features)
But, i get the following error:
DatasetNotFoundError: Dataset smartwatch_gestures not found.
I'm trying to import some regularizers, with the following code:
import tensorflow as tf
from tensorflow import keras
import numpy as np
# importing regularizers
from tf.keras.regularizers import l2, activity_l2
The problem is that I get the following error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_8996/2415362791.py in <module>
4 from tensorflow import keras
5 # importing regularisers
----> 6 from tf.keras.regularizers import l2, activity_l2
ModuleNotFoundError: No module named 'tf'
However, I've already installed TensorFlow, and I can build neural networks, with several layers, without any error showing up...
I'm using Anaconda v2.1, Jupyter Notebooks v6.4.3.
Why is this happening?
You can use tensorflow.keras.regularizers instead of tf.keras.regularizers as below:
from tensorflow.keras.regularizers import l2 (to import specific regularizers)
or
from tensorflow.keras import regularizers (to use and import all other regularizers.)
activity_l2 is deleted and is equal to l2. Find the related github reference here.
I can successfully run the Keras mnist example. I now would like to run the "English-to-Spanish translation with a sequence-to-sequence Transformer" example found here. I'm running TensorFlow 2.5.0
https://colab.research.google.com/github/keras-team/keras-io/blob/master/examples/nlp/ipynb/neural_machine_translation_with_transformer.ipynb#scrollTo=HPyHRZvOO1G1
When I try to import TextVectorization I get the following error:
>>> import pathlib
>>> import random
>>> import string
>>> import re
>>> import numpy as np
>>> import tensorflow as tf
2021-09-01 11:45:11.253159: I tensorflow/stream_executor/platform/default/dso_loader.cc:53]
Successfully opened dynamic library libcudart.so.11.0
>>> from tensorflow import keras
>>> from tensorflow.keras import layers
>>> from tensorflow.keras.layers import TextVectorization
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'TextVectorization' from 'tensorflow.keras.layers'
(/home/users/stren/anaconda3/lib/python3.8/site-packages/tensorflow/keras/layers/__init__.py)
>>> tf.__version__
'2.5.0'
Any ideas what I'm doing wrong?
I faced the same issue with conda.
The solution can be found here
you should import TextVectorization from tensorflow.keras.layers.experimental.preprocessing instead
I am trying to run the following codes:
import os
import pprint
import numpy as np
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.layers import *
from tensorlayer.prepro import *
from random import shuffle
However, I am getting this error:
~\Documents\Jupyter Notebooks far Run\cGAN at Lockdown\Re-implement CycleGAN in
Tensorlayer=GD\CycleGAN_Tensorlayer-master\tensorlayer\layers.py in <module>
31 TF_GRAPHKEYS_VARIABLES = tf.GraphKeys.GLOBAL_VARIABLES
32 except: # For TF11 and before
---> 33 TF_GRAPHKEYS_VARIABLES = tf.GraphKeys.VARIABLES
34
35 ## Variable Operation
AttributeError: module 'tensorflow' has no attribute 'GraphKeys'
The version of my tf is 2.0.0-beta1 while I have installed TensorLayer 2.2.1
Kindly let me know where I am getting it wrong.