( Replace '[ ]' with '[x]' if completed. )
- [x ] I've checked [the issues list](https://github.com/apple/dnikit/issues) to make sure a bug for this is not already filed.
- [x] I've updated to the latest version of DNIKit.
- [x ] I've searched the [documentation](https://apple.github.io/dnikit/index.html), if appropriate, and found no answer.
Please describe what happened and include any failure information you think would be useful (stacktrace, logs, etc.).
WARNING:absl:You are saving your model as an HDF5 file via `model.save()` or `keras.saving.save_model(model)`. This file format is considered legacy. We recommend using instead the native Keras format, e.g. `model.save('my_model.keras')` or `keras.saving.save_model(model, 'my_model.keras')`.
INFO:dnikit_tensorflow.TF2:Instantiating TF2 Model
INFO:dnikit_tensorflow.TF2:GPUs Available: 1
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[18], line 2
1 from dnikit_tensorflow import TFModelWrapper
----> 2 dni_model =TFModelWrapper.from_keras(mobilenet,tf.keras.applications.mobilenet.preprocess_input)
File ~/anaconda3/envs/python3/lib/python3.10/site-packages/dnikit_tensorflow/_sample_models.py:80, in TFModelWrapper.from_keras(cls, model, preprocessing)
62 @classmethod
63 def from_keras(cls,
64 model: tf.keras.Model,
65 preprocessing: t.Callable[[np.ndarray], np.ndarray]) -> 'TFModelWrapper':
66 """
67 Convenience method for loading as :class:`TFModelWrapper`
68 from Keras models and preprocessors.
(...)
77 preprocessing: keras preprocessing function to transform data
78 """
79 return TFModelWrapper(
---> 80 model=cls.load_keras_model(model),
81 preprocessing=Processor(preprocessing)
82 )
File ~/anaconda3/envs/python3/lib/python3.10/site-packages/dnikit_tensorflow/_sample_models.py:95, in TFModelWrapper.load_keras_model(model)
93 model_path = os.path.join(temp_dir, 'model.h5')
94 model.save(model_path)
---> 95 dni_model = load_tf_model_from_path(model_path)
96 return dni_model
File ~/anaconda3/envs/python3/lib/python3.10/site-packages/dnikit_tensorflow/_tensorflow/_tensorflow_loading.py:104, in load_tf_model_from_path(path)
74 def load_tf_model_from_path(path: dt.PathOrStr) -> Model:
75 """
76 Initialize a TensorFlow :class:`Model <dnikit.base.Model>` from a model serialized in ``path``
77
(...)
102 A DNIKit TensorFlow :class:`Model <dnikit.base.Model>`.
103 """
--> 104 return tf_path_load(path)
File ~/anaconda3/envs/python3/lib/python3.10/site-packages/dnikit_tensorflow/_tensorflow/_tf2_loading.py:74, in load_tf_2_model_from_path(path)
71 tf.keras.backend.clear_session()
73 loader = TF2LoadingChain.get_loader(path)
---> 74 return Model(loader.load(pathname=path))
File <string>:4, in __init__(self, _details)
File ~/anaconda3/envs/python3/lib/python3.10/site-packages/dnikit/base/_model.py:199, in Model.__post_init__(self)
195 """
196 Initialize common elements for all dnikit ``Model``.
197 """
198 super().__init__()
--> 199 response_infos = {r.name: r for r in self._details.get_response_infos()}
200 input_layers = {r.name: r for r in self._details.get_input_layer_responses()}
201 object.__setattr__(self, "_response_infos", response_infos)
File ~/anaconda3/envs/python3/lib/python3.10/site-packages/dnikit/base/_model.py:199, in <dictcomp>(.0)
195 """
196 Initialize common elements for all dnikit ``Model``.
197 """
198 super().__init__()
--> 199 response_infos = {r.name: r for r in self._details.get_response_infos()}
200 input_layers = {r.name: r for r in self._details.get_input_layer_responses()}
201 object.__setattr__(self, "_response_infos", response_infos)
File ~/anaconda3/envs/python3/lib/python3.10/site-packages/dnikit_tensorflow/_tensorflow/_tf2_model.py:103, in _Tensorflow2ModelDetails.get_response_infos(self)
98 def get_response_infos(self) -> t.Iterable[ResponseInfo]:
99 # now go through all layers (including input) and return output
100 for layer in self.model.layers:
101 yield ResponseInfo(
102 name=layer.name,
--> 103 dtype=_convert_tf_dtype(layer.output.type_spec.dtype),
104 shape=_convert_tf_shape(layer.output.type_spec.shape),
105 layer=ResponseInfo.Layer(
106 name=_remove_op_number(layer.output.name),
107 kind=_convert_tf_operation(layer.output.name),
108 typename=_extract_kind(layer.output.name)
109 )
110 )
AttributeError: 'KerasTensor' object has no attribute 'type_spec'
This would be the place for related issues, suggestions, links for context, etc.
Python implementation: CPython
Python version : 3.10.14
IPython version : 8.22.2
numpy : 1.26.4
pandas : 2.2.1
tensorflow: 2.16.1
keras : 3.4.1