Comments (2)
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.
Closing this, feel free to reopen if there is additional information/ assistance needed
from decision-forests.
Related Issues (20)
- model_plotter.plot_model_in_colab has No response HOT 3
- How to use tfdf.builder.CARTBuilder to build/train a decision tree by hand HOT 19
- Models trained on pure 1's predict 0 HOT 3
- max_vocab_count won't work for CATEGORICAL integerized in tfdf.keras.GradientBoostedTreesModel HOT 5
- Save and load model with tunning in automatic_tuning_colab.ipynb HOT 4
- Symbol not found, but versions are compatible according to the website HOT 4
- Loading a model returns either an untrained model or broken model HOT 1
- Using call_get_leaves inside @tf.function call in ensemble model inherits from tensorflow.keras.Model HOT 10
- no wheels for apple silicon (macos-arm64) HOT 2
- ANE support through coremltools HOT 4
- Can't use both `sample_weight` and `class_weight` at the same time HOT 1
- Is there a method like ydf.load_model() to load model get a instance of tfdf.keras.RandomForestModel? HOT 2
- decision forests tutorial tf_df_in_tf_js code wasn't working for me
- gpu support for layer use HOT 1
- DistributedGradientBoostedTreesModel does not support Ranking task HOT 1
- TF-DF Compatibility with Keras 3? HOT 6
- make_inspector() throws object of type 'NoneType' has no len() when I retrieve TF DF RF model layer in the hybrid model HOT 3
- tfdf 1.9.0 only compatible with tf 2.16.1 which ships Keras 3 HOT 8
- tensorflow-decision-forests 1.5.0 requires tensorflow~=2.13.0, but you have tensorflow 2.16.1 which is incompatible.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from decision-forests.