Giter Site home page Giter Site logo

apple / dnikit Goto Github PK

View Code? Open in Web Editor NEW
76.0 10.0 6.0 12.18 MB

A Python toolkit for analyzing machine learning models and datasets.

Home Page: https://apple.github.io/dnikit/

License: Apache License 2.0

Makefile 0.23% Python 87.20% Jupyter Notebook 12.57%
fairness-ml introspection machine-learning python ai bias compression data fairness ml data-duplication

dnikit's Introduction

Data and Network Introspection Kit (DNIKit)

A Python toolkit for introspection of machine learning models and datasets.

Please see the complete docs for more information.

Installation

Standard PyPi installation. For installation from a specific branch, see Contributor's Guide.

pip install dnikit

To run the notebook examples, try this instead:

pip install "dnikit[notebook]"

Start the notebook:

jupyter notebook

More installation options can be found in the docs.

dnikit's People

Contributors

mmaherwelsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dnikit's Issues

Error when running a Sample notebook

Bug Report

When I run the sample notebook in the conda environment, I get this error

AttributeError: 'KerasTensor' object has no attribute 'type_spec'

I think the error is due to use of type_spec here

One sentence summary of PR:
Unable to run sample notebook

Checklist

( 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.

Description

Expected Behavior

What were you trying to do and what did you expect to happen?
The notebook should run as expected.

Current Behavior

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'

Possible Solution, if applicable

This would be the place for related issues, suggestions, links for context, etc.

Environment Setup

  • Python Version:
  • My env
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
  • MacOS or Linux: Linux
  • For general users - Version of DNIKit: 2.0.0
  • For developers - Branch of DNIKit / commit ID (if not latest commit): Latest
  • DNIKit Virtualenv? (Yes/No): conda env
  • Additional dependencies (attach your pip freeze):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.