Giter VIP home page Giter VIP logo

Comments (2)

achoum avatar achoum commented on June 8, 2024

Unfortunately in TensorFlow, a loaded model is not equivalent to an original model. An original model contains several utilities to automatically convert and adapt dataset format, while a loaded model is very restrictive and specific.

The error:

ValueError: Could not find matching concrete function to call loaded from the SavedModel. Got:
      Positional arguments (2 total):
        * OrderedDict([('MPG', <tf.Tensor 'inputs:0' shape=(None, 1) dtype=float32>),
                 ('Cylinders',
                  <tf.Tensor 'inputs_1:0' shape=(None, 1) dtype=int32>),
                 ('Displacement',
                  <tf.Tensor 'inputs_2:0' shape=(None, 1) dtype=float32>),
                 ('Horsepower',
                  <tf.Tensor 'inputs_3:0' shape=(None, 1) dtype=float32>),
                 ('Weight', <tf.Tensor 'inputs_4:0' shape=(None, 1) dtype=float32>),
                 ('Acceleration',
                  <tf.Tensor 'inputs_5:0' shape=(None, 1) dtype=float32>),
                 ('year', <tf.Tensor 'inputs_6:0' shape=(None, 1) dtype=int32>),
                 ('Origin', <tf.Tensor 'inputs_7:0' shape=(None, 1) dtype=int32>)])
        * False
      Keyword arguments: {}
    
     Expected these arguments to match one of the following 2 option(s):
    
    Option 1:
      Positional arguments (2 total):
        * {'Acceleration': TensorSpec(shape=(None,), dtype=tf.float32, name='Acceleration'),
     'Cylinders': TensorSpec(shape=(None,), dtype=tf.float32, name='Cylinders'),
     'Horsepower': TensorSpec(shape=(None,), dtype=tf.float32, name='Horsepower'),
     'MPG': TensorSpec(shape=(None,), dtype=tf.float32, name='MPG'),
     'Origin': TensorSpec(shape=(None,), dtype=tf.float32, name='Origin'),
     'Weight': TensorSpec(shape=(None,), dtype=tf.float32, name='Weight'),
     'year': TensorSpec(shape=(None,), dtype=tf.float32, name='year')}
        * True
      Keyword arguments: {}

Indicates that the provided dataset does not match what the model expects:

  • The dataset should contain a dictionary of Tensorflow (instead of OrderedDict of Tensorflow).
  • The label "'Displacement'" column should not be provided (it does not make sense to feed the label to the model for inference).
  • The dtype are wrong. By default TF-DF encodes all the numerical features as float32. Instead, it seems that make_csv_dataset interprets some of those values as integers.

Here is a proposed fix of those 3 issues:

for batch in ds.batch(3).take(1):
	
    clean_batch = dict(batch)

    for k in clean_batch:
      clean_batch[k] = tf.cast(tf.squeeze(clean_batch[k]), tf.float32)

    del clean_batch["Displacement"]

    print(clean_batch)
    print(model_loaded.predict(clean_batch))

Result:

{'MPG': <tf.Tensor: shape=(3,), dtype=float32, numpy=array([18. , 30.9, 26. ], dtype=float32)>, 'Cylinders': <tf.Tensor: shape=(3,), dtype=float32, numpy=array([6., 4., 4.], dtype=float32)>, 'Horsepower': <tf.Tensor: shape=(3,), dtype=float32, numpy=array([88., 75., 93.], dtype=float32)>, 'Weight': <tf.Tensor: shape=(3,), dtype=float32, numpy=array([3021., 2230., 2391.], dtype=float32)>, 'Acceleration': <tf.Tensor: shape=(3,), dtype=float32, numpy=array([16.5, 14.5, 15.5], dtype=float32)>, 'year': <tf.Tensor: shape=(3,), dtype=float32, numpy=array([73., 78., 74.], dtype=float32)>, 'Origin': <tf.Tensor: shape=(3,), dtype=float32, numpy=array([1., 1., 3.], dtype=float32)>}
1/1 [==============================] - 0s 51ms/step
[[221.37837 ]
 [110.83273 ]
 [107.609535]]

from decision-forests.

rstz avatar rstz commented on June 8, 2024

Closing this, feel free to reopen if there is additional information/ assistance needed

from decision-forests.

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.