tfjs
tfjs copied to clipboard
`tf.lookup` object conversion doesn't work as expected
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): This repo contains all the reproducible code. In a nutshell, here is the code:
table = tf.lookup.StaticHashTable(...)
inputs = [keras.Input((1,), dtype=tf.string, name='feature')]
model = keras.Model( inputs = inputs, output = table.lookup(inputs[0]))
tf.saved_model.save(model, ...)
!tensorflowjs_converter \
--input_format=tf_saved_model \
--output_format=tfjs_graph_model \
tf_model \
tfjs_model
On the JS side, we have:
let model = await tf.loadGraphModel(`tfjs_model/model.json')
let input = {"feature":tf.tensor(['Class A'],shape=[1,1],dtype='string')}
let output = await model.executeAsync(input) // Errors out
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 21.10
- TensorFlow.js installed from (npm or script link):
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script>
- TensorFlow.js version (use command below): 3.17.0
- Browser version: Google Chrome 101.0.4951.64
- Tensorflow.js Converter Version: tensorflowjs 3.15.0
Dependency versions: keras 2.9.0 tensorflow 2.9.0
Describe the current behavior The saved model (in tf) works as expected. No errors. However, the TFJS model throws this error:
Uncaught (in promise) Error: Cannot compute the outputs [Identity] from the provided inputs [feature:0]. Consider providing the following inputs: [unknown]. Alternatively, to avoid the dynamic ops, use model.execute() and specify the inputs [Identity]
at e.<anonymous> (graph_executor.js:520:13)
at c (runtime.js:63:40)
at Generator._invoke (runtime.js:293:22)
at Generator.next (runtime.js:118:21)
at bv (runtime.js:747:43)
at o (runtime.js:747:43)
Then, when I change the input like this:
let input = {
"feature":tf.tensor(['Class A'],shape=[1,1],dtype='string'),
'unknown': tf.tensor(3),
}
It throws this error:
hash_table_executor.js:66 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'find')
at hash_table_executor.js:66:31
at c (runtime.js:63:40)
at Generator._invoke (runtime.js:293:22)
at Generator.next (runtime.js:118:21)
at bv (runtime.js:747:43)
at o (runtime.js:747:43)
at runtime.js:747:43
at new Promise (<anonymous>)
at runtime.js:747:43
at hash_table_executor.js:78:41
At this point I have no idea how to proceed.
Since the required ops are supported, the problem seems to be in tfjs converter. Somehow it doesn't remember store the data stored in lookup objects.
Describe the expected behavior The model should be able to correctly convert lookup objects and not error out. Otherwise, we should update the docs to state how to work around this problem. I'm open to suggestions here.
Standalone code to reproduce the issue
This repo contains all the code to reproduce the error. Just run the main.ipynb
, followed by running the index.html
. I'll make this into a colab notebook if necessary.
@rthadur Any updates on this? Could you replicate this bug?
@tornikeo The issue is with TF2 table support, we are working on fixing the issue
Should be fixed with the newest release