GithubHelp home page GithubHelp logo

Comments (6)

rlcauvin avatar rlcauvin commented on June 12, 2024

Inspecting the code for TextVectorization (https://github.com/keras-team/keras/blob/master/keras/layers/preprocessing/text_vectorization.py#L491) and deserialize_keras_object (https://github.com/keras-team/keras/blob/master/keras/saving/serialization_lib.py#L392), I see that there is no way the proper logic for deserializing the split function will run. The deserialization code looks for if module_objects is not None:, but TextVectorization.from_config() doesn't pass a module_objects parameter to deserialize_keras_object, so that code block doesn't execute.

As a workaround, I extended the tf.keras.layers.TextVectorization class with:

class PatchedTextVectorization(tf.keras.layers.TextVectorization):

  @classmethod
  def from_config(cls, config):
    if not isinstance(config["standardize"], str):
      config["standardize"] = tf.keras.saving.deserialize_keras_object(config["standardize"])
    if not isinstance(config["split"], str):
      config["split"] = tf.keras.saving.deserialize_keras_object(config["split"], module_objects = [])

    return cls(**config)

Cloning an instance of PatchedTextVectorization constructed with the split function works fine. You can see I shoehorned module_objects = [] into its invocation of tf.keras.saving.deserialize_keras_object.

from tf-keras.

tilakrayal avatar tilakrayal commented on June 12, 2024

@sachinprasadhs,
I was able to reproduce the issue on tensorflow v2.14, v2.15. Kindly find the gist of it here.

from tf-keras.

sachinprasadhs avatar sachinprasadhs commented on June 12, 2024

@rlcauvin , From TensorFlow 2.16, Keras 3 will be the backend for tf.keras, I see this is working fine with Keras 3, that should fix your issue, is there any specific reason you're using tf.keras with 2.15?
You can use tensorflow 2.15 and Keras 3 as well.
install tensorflow first and then install keras 3.

from tf-keras.

github-actions avatar github-actions commented on June 12, 2024

This issue is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

from tf-keras.

rlcauvin avatar rlcauvin commented on June 12, 2024

Thank you, @sachinprasadhs. Using !pip install -U keras to install Keras 3 worked for that isolated case. However, I want to use tensorflow_decision_forests. Unfortunately, import tensorflow_decision_forests as tfdf results in the error below. Please see the modified Google Colab notebook for the full code.

[/usr/local/lib/python3.10/dist-packages/tensorflow_decision_forests/keras/core.py](https://localhost:8080/#) in <module>
     75   # tf>1.12
---> 76   import keras.src.engine.data_adapter as data_adapter
     77 except ImportError:

ModuleNotFoundError: No module named 'keras.src.engine'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
3 frames
[<ipython-input-3-b4486e63aff0>](https://localhost:8080/#) in <cell line: 1>()
----> 1 import tensorflow_decision_forests as tfdf
      2 import tensorflow as tf
      3 from typing import Text

[/usr/local/lib/python3.10/dist-packages/tensorflow_decision_forests/__init__.py](https://localhost:8080/#) in <module>
     62 check_version.check_version(__version__, compatible_tf_versions)
     63 
---> 64 from tensorflow_decision_forests import keras
     65 from tensorflow_decision_forests.component import py_tree
     66 from tensorflow_decision_forests.component.builder import builder

[/usr/local/lib/python3.10/dist-packages/tensorflow_decision_forests/keras/__init__.py](https://localhost:8080/#) in <module>
     51 from typing import Callable, List
     52 
---> 53 from tensorflow_decision_forests.keras import core
     54 from tensorflow_decision_forests.keras import wrappers
     55 

[/usr/local/lib/python3.10/dist-packages/tensorflow_decision_forests/keras/core.py](https://localhost:8080/#) in <module>
     77 except ImportError:
     78   # tf<=1.12
---> 79   import keras.engine.data_adapter as data_adapter
     80 get_data_handler = data_adapter.get_data_handler
     81 

ModuleNotFoundError: No module named 'keras.engine'

from tf-keras.

nkovela1 avatar nkovela1 commented on June 12, 2024

Fixed in this commit! Thank you, closing this issue.

from tf-keras.

Related Issues (20)

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.