tfjs: tfjs-node support for saved models does not recognize valid dtypes
Simply calling tfnode.node.getMetaGraphsFromSavedModel(path); on a model using uint8 results in error:
(node:2420) UnhandledPromiseRejectionWarning: Error: Unsupported tensor DataType: DT_UINT8, try to modify the model in python to convert the datatype
at mapTFDtypeToJSDtype (/home/vlado/dev/test-tfjs/node_modules/@tensorflow/tfjs-node/dist/saved_model.js:465:19)
However, support for unint8 was added to tfjs via https://github.com/tensorflow/tfjs/pull/2981 back in March.
Those newly supported data types should be added throughout tfjs codebase.
Environment: Ubuntu 20.04 running NodeJS 14.9.0 with TFJS 2.3.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (8 by maintainers)
@loretoparisi The model expects an encoded word vector as input, while the Universal Sentence Encoder (USE) model returns embeddings.
Basically, you’ll want to use the
loadTokenizer()function from the previous USE version, but that one requires TFJS 1.x… I have a working version locally, but it’d be better to fix theexamples instead - see Issuemodel repoUnfortunately @pyu10055’s commit b02310745ceac6b8e4a475719c343da53e3cade2 on the USE-repo broke both the Toxicity
examplemodel and your use-case entirely…The real problem is that the examples are outdated and some changes broke TFJS 2.x compatibility (in the case of USE I fail to see the reasoning behind the change - might have been a mistake?).
Meanwhile, I’ll create a gist for you that contains all you need to get this working as a single-file solution. I’ll get back to you in a bit.
EDIT: I got confused here, since a similar issue was raised w.r.t. outdated tfjs-examples. The same applies to tfjs-models, though - basically some models are incompatible with TFJS 2.x due to package changes (not for technical reasons).
@loretoparisi btw, one advantage of working with
saved_modelandgetMetaGraphsFromSavedModel()is that it shows actual signature names instead just an incrementing array (when model has multiple inputs and/or outputs) that you get from agraph_model.See https://github.com/tensorflow/tfjs/issues/3942 for details.
@loretoparisi I’ll create a pull-request that implements
outputs()andinputs()onSavedModel.@loretoparisi Interesting. I used the following code and it worked just fine:
The model methods
outputs()andinputs()aren’t implemented yet for theSavmedModel-class, but in case you need them for some reason, outputs and inputs can be obtained using thegetMetaGraphsFromSavedModel()andgetSignatureDefEntryFromMetaGraphInfo()functions.@loretoparisi Yup, I’ve reported that under https://github.com/tensorflow/tfjs/issues/4004 and it was just fixed in https://github.com/tensorflow/tfjs/pull/4008