The Array of Tensors that you are passing to your model is not the size the the model expected

running node v16.15.1, tfjs-node v4.1.0 on Mac Big Sur

The model loaded with no error, failed on model.predict()
ValueError: Error when checking model : the Array of Tensors that you are passing to your model is not the size the the model expected. Expected to see 1 Tensor(s), but instead got 0 Tensors(s).

       model = await tfnode.loadLayersModel(`file://${modelPath}/model.json`)
       console.log(`loading time:  ${modelPath}, ${endTime-startTime}`);

       let outputTensor = model.predict({input_tensor: inputTensor});

@playground looks like your inputTensor is not a Tensor.

Can you try the following:

model.predict(inputTensor);
model.predict(tf.tensor(inputTensor));

Feel free to post a console log of

console.log(inputTensor);   
inputTensor.print();     
model.summary();

@Dennis

model.predict(inputTensor);

ValueError: Error when checking : expected conv2d_Conv2D1_input to have shape [null,28,28,1] but got array with shape [1,720,1280,3].
    at new ValueError (/model-service/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:276:28)
    at checkInputData (/model-service/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:32814:31)
    at LayersModel.predict (/model-service/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:33492:9)
    at Sequential.predict (/model-service/node_modules/@tensorflow/tfjs-layers/dist/tf-layers.node.js:35309:27)
    at Observable._subscribe (/model-service/index.js:155:32)
    at Observable._trySubscribe (/model-service/node_modules/rxjs/dist/cjs/internal/Observable.js:71:25)
    at Observable.subscribe (/model-service/node_modules/rxjs/dist/cjs/internal/Observable.js:36:30)
    at _loop_1 (/model-service/node_modules/rxjs/dist/cjs/internal/observable/forkJoin.js:29:52)
    at Observable._subscribe (/model-service/node_modules/rxjs/dist/cjs/internal/observable/forkJoin.js:45:13)
    at Observable._trySubscribe (/model-service/node_modules/rxjs/dist/cjs/internal/Observable.js:71:25)

if tried with model.predict(inputTensor.reshape([null,28,28,1]))

Error: Invalid TF_Status: 3
Message: Input to reshape is a tensor with 2764800 values, but the requested shape has 0

model.predict(tf.tensor(inputTensor));

Error: values passed to tensor(values) must be a number/boolean/string or an array of numbers/booleans/strings, or a TypedArray
    at makeTensor (/model-service/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:5620:15)
    at Object.tensor (/model-service/node_modules/@tensorflow/tfjs-core/dist/tf-core.node.js:5758:12)
    at Observable._subscribe (/model-service/index.js:156:47)
    at Observable._trySubscribe (/model-service/node_modules/rxjs/dist/cjs/internal/Observable.js:71:25)
    at Observable.subscribe (/model-service/node_modules/rxjs/dist/cjs/internal/Observable.js:36:30)
    at _loop_1 (/model-service/node_modules/rxjs/dist/cjs/internal/observable/forkJoin.js:29:52)
    at Observable._subscribe (/model-service/node_modules/rxjs/dist/cjs/internal/observable/forkJoin.js:45:13)
    at Observable._trySubscribe (/model-service/node_modules/rxjs/dist/cjs/internal/Observable.js:71:25)
    at Observable.subscribe (/model-service/node_modules/rxjs/dist/cjs/internal/Observable.js:36:30)

@playground you need to resize the input image.
e.g. you can use the tf.images operations.

// Shape: [1, 720, 1280, 3]
// Mean the RGB Channels to one grayscale dimension
grayTensor = inputTensor.mean(2).toFloat().expandDims(-1);

// Shape: [1, 720, 1280, 1]
// Linear Resize/scale your image to 28x28
resizedTensor = tf.image.resizeBilinear(grayTensor, [28,28]);
// outputs: [1, 28, 28, 1]

model.predict(resizedTensor);
1 Like