compatibility issues for Tensorflow federated in Google colab - tensorflow

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?

Related

issue while using segmentation-models library

from tensorflow import keras
from segmentation_models import PSPNet
While running this, I am facing the error below:
AttributeError Traceback (most recent call last)
<ipython-input-14-fbd9360b4944> in <module>()
1
2 from tensorflow import keras
----> 3 from segmentation_models import PSPNet
3 frames
/usr/local/lib/python3.6/dist-packages/segmentation_models/__init__.py in <module>()
96 _framework = os.environ.get('SM_FRAMEWORK', _DEFAULT_KERAS_FRAMEWORK)
97 try:
---> 98 set_framework(_framework)
99 except ImportError:
100 other = _TF_KERAS_FRAMEWORK_NAME if _framework == _KERAS_FRAMEWORK_NAME else _KERAS_FRAMEWORK_NAME
/usr/local/lib/python3.6/dist-packages/segmentation_models/__init__.py in set_framework(name)
66 if name == _KERAS_FRAMEWORK_NAME:
67 import keras
---> 68 import efficientnet.keras # init custom objects
69 elif name == _TF_KERAS_FRAMEWORK_NAME:
70 from tensorflow import keras
/usr/local/lib/python3.6/dist-packages/efficientnet/keras.py in <module>()
15 preprocess_input = inject_keras_modules(model.preprocess_input)
16
---> 17 init_keras_custom_objects()
/usr/local/lib/python3.6/dist-packages/efficientnet/__init__.py in init_keras_custom_objects()
69 }
70
---> 71 keras.utils.generic_utils.get_custom_objects().update(custom_objects)
72
73
AttributeError: module 'keras.utils' has no attribute 'generic_utils'
I installed segmentation-models library using pip as the provided instruction (link)
I would be appreciated if someone can help me with how to fix it. I simply copy the code from the instruction, and all I found on the net was just the same. Should it be something wrong with the installation?
Please guide me through this!:)
You are facing this issue because you are using Tensorflow version >= 2.2. To fix this problem either you have to use Tensorflow 2.1/2.0 or Tensorflow 1.x (i.e 1.15.2)
Please follow below steps to perform Image segmentation using Segmentation models using TF 2.1.
!pip install q tensorflow==2.1
!pip install segmentation-models
import tensorflow as tf
from segmentation_models import PSPNet
#Instantiate PSPNet model
model = PSPNet()
#Display model summary
model.summary()

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'

Colab upgraded to TensorFlow 2.0, now am experiencing an error RuntimeError: version does not support TensorFlow 2.0

I have been running my DL models on colab well, until they upgraded the system last Friday.
I get this error:
AttributeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
65 try:
---> 66 return tf.get_default_graph()
67 except AttributeError:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
8 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
67 except AttributeError:
68 raise RuntimeError(
---> 69 'It looks like you are trying to use '
70 'a version of multi-backend Keras that '
71 'does not support TensorFlow 2.0. We recommend '
RuntimeError: It looks like you are trying to use a version of multi-backend Keras that does not support TensorFlow 2.0. We recommend using tf.keras, or alternatively, downgrading to TensorFlow 1.14.
I am currently running Python 3.7.6 version on my Mac(Mojave).
I am running TensorFlow 2.0.0 version on my machine.
I too had the same issue while using the Google Colab.
So what I did was, imported all the modules from the tensorflow.keras modules, instead of using the traditional method of calling via keras only.
eg. instead of from keras.models import Sequential
use
from tensorflow.keras import Sequential
And,
from keras.layers import Conv2D, MaxPool2D, Dense, Flatten, Dropout use
from tensorflow.keras.layers import Conv2D, MaxPool2D, Flatten, Dropout, Dense
So, my new code looks like this. My new code.
Try using from tensorflow.keras.models import Model
And make sure that all the Keras modules imported are of the same version.
Don't use
from tensorflow.keras.models import Model
and
from Keras import layers,
while building NN in the same notebook else it keeps on throwing some errors.
This solution helped me.

Keras and Tensorflow: UnboundLocalError: local variable 'self' referenced before assignment

I am following a tutorial for TensorFlow and Keras.
When I run the following syntax:
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(units=64, activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax'))
(This is not full stacktrace as StackOverflow wont let me saying it has code only)
I get following error:
--------------------------------------------------------------------
UnboundLocalError Traceback (most recent call last)
<ipython-input-49-30ebc8793948> in <module>()
5 from keras.layers import Dense
6
----> 7 model.add(Dense(units=64, activation='relu', input_dim=100))
--> 164 layer(x)
165 set_inputs = True
166 else:
/usr/local/lib/python3.7/site-packages/keras/initializers.py in __call__(self, shape, dtype)
self._message_listener.Modified()
UnboundLocalError: local variable 'self' referenced before assignment
Could this be because of python 3.7?
Yes, I had to uninstall and reinstall Python 3.6. Python 3.7 looks like it introduces unexpected behavior. Thankfully, my issue is now resolved.
I had the same issue. The problem seemed to be with python 3.7. Instead of uninstalling 3.7 and installing 3.6 I downloaded anaconda, created a virtual environment for 3.6 along with all the other dependancies.

CoreMLTools Keras simple Sequential Linear Regression model export error ('module' object has no attribute 'mobilenet')

I've created a very simple Sequential Linear Regression model using Keras 2.0.4 (TensorFlow 1.1.0 backend) and my coremltools (0.6.3) export is failing with this error message:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in () ----> 1 coreml_model = coremltools.converters.keras.convert(model, input_names="input", output_names="output") /Users/Jacopo/anaconda/envs/KerasTensorFlowCoreML/lib/python2.7/site-packages/coremltools/converters/keras/_keras_converter.pyc in convert(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, predicted_probabilities_output) 489 predicted_probabilities_output = predicted_probabilities_output) 490 elif _HAS_KERAS2_TF: --> 491 from . import _keras2_converter 492 return _keras2_converter._convert(model = model, 493 input_names = input_names, /Users/Jacopo/anaconda/envs/KerasTensorFlowCoreML/lib/python2.7/site-packages/coremltools/converters/keras/_keras2_converter.py in () 66 _keras.layers.wrappers.TimeDistributed:_layers2.default_skip, 67 ---> 68 _keras.applications.mobilenet.DepthwiseConv2D:_layers2.convert_convolution, 69 70 } AttributeError: 'module' object has no attribute 'mobilenet'
I'm using Python 2.7 on macOS
As said this is a very simple Linear Regression and the module has no image input at all.
Any hint ?
Thanks, Jacopo
Updating Keras to 2.0.6 worked for me...
coremltools works when keras uses tensorflow, not theano, as its backend.
you can change keras' default backend at $HOME/.keras/keras.json, and changing to "backend": "tensorflow".