AttributeError: 'TensorSliceDataset' object has no attribute "'element_spec'" - tensorflow

I am very new to tensorflow. I ran following code -
import tensorflow as tf
d = tf.data.Dataset.from_tensor_slices(tf.random.uniform([3,6]))
d.element_spec
And got following error -
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-a00819363729> in <module>()
1 import tensorflow as tf
2 d = tf.data.Dataset.from_tensor_slices(tf.random.uniform([3,6]))
----> 3 d.element_spec
AttributeError: 'TensorSliceDataset' object has no attribute 'element_spec'
I cannot find solution for this error. I just want to print the type of each element component in variable d. What is going wrong here??
I am using tensorflow 2.0.

Related

compatibility issues for Tensorflow federated in Google colab

TypeError Traceback (most recent call last)
in
5 import numpy as np
6 import tensorflow as tf
----> 7 import tensorflow_federated as tff
14 frames
/usr/lib/python3.8/typing.py in _type_check(arg, msg, is_argument)
147 return arg
148 if not callable(arg):
--> 149 raise TypeError(f"{msg} Got {arg!r:.100}.")
150 return arg
151
TypeError: Callable[[arg, ...], result]: each arg must be a type. Got Ellipsis.
I'm getting this error while trying to import tensorflow_federated in Colab.
I have tried installing lower compatible versions of tensorflow and tensorflow_federated, but nothing works. Can someone else also faced this problem? and Do anyone know how to fix it?

load TFlite model and quantizate

I would like to load a tflite model and quantize it but seems the model that is loaded does not have the right object class attributes.
here is my code
interpreter = tf.lite.TFLiteConverter.from_saved_model('efficientdet_d0_coco17_tpu-32/saved_model')
config = QuantizationConfig.for_float16()
interpreter.export(export_dir='.', tflite_filename='x_model_fp16.tflite', quantization_config=config)
error
AttributeError Traceback (most recent call last)
<ipython-input-14-19596da94f3d> in <module>
----> 1 interpreter.export(export_dir='.', tflite_filename='/content/drive/Othercomputers/intel16/botri/efficient_net/x_model_fp16.tflite', quantization_config=config)
AttributeError: 'TFLiteSavedModelConverterV2' object has no attribute 'export'
I also have tried to load tflite format file but the error stays the same.

Tensorflow: How to load an object detection model and viewing the model's architecture?

I am trying to load a object detection model and viewing the architecture because I need to know what my input and output layers are in order to convert the model format to a different format.
Right now, I am trying to do:
model = tf.saved_model.load('/content/drive/MyDrive/my_ssd_mobnet_640x640_tuned/tfliteexport/saved_model')
model.summary()
And am getting this error:
AttributeError Traceback (most recent call last)
<ipython-input-18-5f15418b3570> in <module>()
----> 1 model.summary()
AttributeError: '_UserObject' object has no attribute 'summary'
My model is in .pb, but I do also have a .tflite version as well.
According to the documentation, you should load the model as keras model, like this:
model = keras.models.load_model("my/path/saved_model")
The .pb version should work.

ImportError: cannot import name 'to_categorical' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)

I have just got below error from an import that use to work fine few hours ago going downward.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-33-4c52b67c20bf> in <module>()
1 import keras
----> 2 from keras.utils import to_categorical
ImportError: cannot import name 'to_categorical' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
Is Keras busy with Update to have this method deprecated?
use this
from tensorflow.keras.utils import to_categorical
instead of
from keras.utils import to_categorical

I'm coding in colab using tensorflow. I'm encountered with this error. How do I proceed. I tried installing various versions of tf as well as tf.hub

feature_extractor = hub.KerasLayer(MODULE_HANDLE,
input_shape=IMAGE_SIZE + (3,),
output_shape=[FV_SIZE])
Error: ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-45-4be659037f32> in <module>()
1 feature_extractor = hub.KerasLayer(MODULE_HANDLE,
2 input_shape=IMAGE_SIZE + (3,),
----> 3 output_shape=[FV_SIZE]
4 )
1 frames
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/variables.py in hash(self)
TypeError: Variable is unhashable if Tensor equality is enabled. Instead, use tensor.experimental_ref() as the key.
Use your TensorFlow hub as latest like 0.10.0
it will solve this
!pip install 'tensorflow-hub == 0.10.0'