Error Messages:
File ~/apps/miniconda3/envs/oscar_py39_tf28/lib/python3.9/site-packages/keras/utils/traceback_utils.py:67, in filter_traceback..error_handler(*args, **kwargs) 65 except Exception as e: # pylint: disable=broad-except 66 filtered_tb = _process_traceback_frames(e.__traceback__) ---> 67 raise e.with_traceback(filtered_tb) from None 68 finally: 69 del filtered_tb File ~/apps/miniconda3/envs/oscar_py39_tf28/lib/python3.9/site-packages/tensorflow/python/framework/func_graph.py:1147, in func_graph_from_py_func..autograph_handler(*args, **kwargs) 1145 except Exception as e: # pylint:disable=broad-except 1146 if hasattr(e, "ag_error_metadata"): -> 1147 raise e.ag_error_metadata.to_exception(e) 1148 else: 1149 raise ValueError: in user code: ValueError: A tf.Variable created inside your tf.function has been garbage-collected. Your code needs to keep Python references to variables created inside `tf.function`s. A common way to raise this error is to create and return a variable only referenced inside your function: @tf.function def f(): v = tf.Variable(1.0) return v v = f() # Crashes with this error message! The reason this crashes is that @tf.function annotated function returns a **`tf.Tensor`** with the **value** of the variable when the function is called rather than the variable instance itself. As such there is no code holding a reference to the `v` created inside the function and Python garbage collects it. The simplest way to fix this issue is to create variables outside the function and capture them: v = tf.Variable(1.0) @tf.function def f(): return v f() # v.assign_add(1.) f() #
Solution:
Modify the path that you import package.
Modify
from keras.layers import Layer, InputSpec
to
from tensorflow.python.keras.engine.base_layer import Layer, InputSpec
Similar Posts:
- [Solved] module ‘keras.engine.topology’ has no attribute ‘load_weights_from_hdf5_group_by_name…
- [Solved] Python TensorFlow Error: ‘tensorflow.compat.v2.__internal__’ has no attribute ‘tf2’
- Tensorflow error due to uninitialized variable [How to Fix]
- [Solved] TensorFlow Error: InternalError: Failed copying input tensor
- ImportError: cannot import name’e.g. utils’from’tensorflow.as.utils’ 38382;’ 39064;
- Django startup error: generator expression must be parentized
- How to Solve Python TypeError: ‘list’ object is not callable
- Python Standard Library: functools (cmp_to_key, lru_cache, total_ordering, partial, partialmethod, reduce, sing…
- Conda Install Library Error: failed with initial frozen solve. Retrying with flexible solve.
- Strange frame error caused by incorrect use of flash. Redirect (‘/ path’) in flash