Skip to content

tensorflow:AutoGraph could not transform saved model #423

Open
@horlar1

Description

@horlar1

Hi @skeydan @dfalbel

I'm having issues with input shape while loading bert with layer_hub. i'm using the example on this page. https://tensorflow.rstudio.com/guide/tfhub/examples/text_classification/

Here is my code and error while trying to pass the input to the embeddings
library(keras)
library(tfhub)
library(readr)

#Build the model ---------------------------------------------------------
#We the token based text embedding trained on English Google News 130GB
#https://tfhub.dev/google/tf2-preview/gnews-swivel-20dim/1
#The model is available at the above URL.
embeddings <- layer_hub(
handle = "https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/2",
trainable = TRUE)

input <- layer_input(shape =shape(), dtype = "string", name = "input")

output <- input %>%
embeddings() %>%
layer_dense(units = 1, activation = "sigmoid")

model <- keras_model(input, output)

ERROR MESSAGE
WARNING:tensorflow:AutoGraph could not transform <tensorflow.python.saved_model.function_deserialization.RestoredFunction object at 0x000001D5C3EEAB70> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output.
Cause: Could not find matching function to call loaded from the SavedModel. Got:
Positional arguments (3 total):

  • Tensor("inputs:0", shape=(None,), dtype=string)
  • True
  • None
    Keyword arguments: {}

Expected these arguments to match one of the following 4 option(s):

Option 1:
Positional arguments (3 total):

  • [TensorSpec(shape=(None, None), dtype=tf.int32, name='inputs/0'), TensorSpec(shape=(None, None), dtype=tf.int32, name='inputs/1'), TensorSpec(shape=(None, None), dtype=tf.int32, name='inputs/2')]
  • False
  • None
    Keyword arguments: {}

Option 2:
Positional arguments (3 total):

  • [TensorSpec(shape=(None, None), dtype=tf.int32, name='input_word_ids'), TensorSpec(shape=(None, None), dtype=tf.int32, name='input_mask'), TensorSpec(shape=(None, None), dtype=tf.int32, name='input_type_ids')]
  • True
  • None
    Keyword arguments: {}

Option 3:
Positional arguments (3 total):

  • [TensorSpec(shape=(None, None), dtype=tf.int32, name='inputs/0'), TensorSpec(shape=(None, None), dtype=tf.int32, name='inputs/1'), TensorSpec(shape=(None, None), dtype=tf.int32, name='inputs/2')]
  • True
  • None
    Keyword arguments: {}

Option 4:
Positional arguments (3 total):

  • [TensorSpec(shape=(None, None), dtype=tf.int32, name='input_word_ids'), TensorSpec(shape=(None, None), dtype=tf.int32, name='input_mask'), TensorSpec(shape=(None, None), dtype=tf.int32, name='input_type_ids')]
  • False
  • None
    Keyword arguments: {}
    Error in py_call_impl(callable, dots$args, dots$keywords) :
    ValueError: in converted code:
    C:\Users..\AppData\Local\Continuum\anaconda3\envs\r-reticulate\lib\site-packages\tensorflow_hub\keras_layer.py:229 call *
    result = smart_cond.smart_cond(training,
    C:\Users.\AppData\Local\Continuum\anaconda3\envs\r-reticulate\lib\site-packages\tensorflow_core\python\framework\smart_cond.py:59 smart_cond
    name=name)
    C:\Users.\AppData\Local\Continuum\anaconda3\envs\r-reticulate\lib\site-packages\tensorflow_core\python\saved_model\load.py:438 _call_attribute
    return instance.call(*args, **kwargs)
    C:\Users.\AppData\Local\Continuum\anaconda3\envs\r-reticulate\lib\site-packages\tensorflow_core\python\eager\def_function.py:568 call
    result = self._call(*args, **kwds)
    C:\Users.\AppData\Local\Continuum\anaconda3\envs\r-reticulate\lib\site-packages\tensorflow_core\python\eager\def_function.py:606 _call
    results = self._stat

Kindly assist.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions