Open stanleyjzheng opened 3 years ago
Hi, @stanleyjzheng
Apologize for the delayed response and I tried to replicate this issue with latest version of @tensorflow/tfjs-node
and tensorflowjs@4.6.0
and I got below error message so we'll have to dig more into this issue and we'll update you soon, Thank you for noticing this issue and I really appreciate your efforts and time. Thank you!
CC :@mattsoulanille
Here is error log :
gaikwadrahul-macbookpro:TFJS gaikwadrahul$ node test.js
Platform node has already been set. Overwriting the platform with node.
/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:273
var _this = _super.call(this, message) || this;
^
ValueError: Input 0 is incompatible with layer conv_preds: expected ndim=4, found ndim=2
at new ValueError (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:273:28)
at Layer.assertInputCompatibility (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:3020:27)
at /Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:3263:19
at nameScope (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:978:19)
at Layer.apply (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:3222:16)
at processNode (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:22341:23)
at Container.fromConfig (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:22402:33)
at deserializeKerasObject (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:674:29)
at deserialize (/Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:20073:12)
at /Users/gaikwadrahul/Desktop/TFJS/node_modules/@tensorflow/tfjs/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:25604:29
Node.js v18.15.0
System information
Describe the current behavior When loading a Keras-converted model using
tf.loadLayersModel
, training causes a shape mismatch not observed during inference. Commonly occurs aroundglobalAveragePooling2d
andglobalMaxPooling2d
.Standalone code to reproduce the issue A minimal example would be to convert mobilenet (I understand this is a part of tfjs-models, but as a demonstration) from Tensorflow application's implementation into tensorflow.js, and try to train on a random input. We first save the model, then convert it with
tensorflowjs_converter
.To save mobilenet with python:
Then to convert it to tensorflow.js:
tensorflowjs_converter --input_format=keras mobilenet.h5 mobilenet
Finally, we can load mobilenet into JavaScript and observe the error
Output:
Inference works, but not training. The origin of the shape 200704 is the shape of the input of the globalAveragePooling2d layer -
batch_size * 1024 * 7 * 7
. In python, shapes are all identical and work in training.This is observed around
globalAveragePooling2d
andglobalMaxPooling2d
in many models - including the official Tensorflow Applications implementations of Mobilenetv2 and Efficientnet, though no example is provided since their implementations are much longer.Other info / logs Traceback: