I created this model for image classification; however, when I try to pass the image
path through model.predict(), I receive this error:
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 9 Tensors(s).
Is there any way to decrease the number of tensors going through the function, or correctly format the image in tensors to pass through and return a prediction?
I’ve looked everywhere, and other questions similar to this didn’t cover my use case in node.js. Any help or nudge in the right direction is welcome
Below is my model.json file, the model I created for image classification.
index.js is what I run through node.js to supposedly give a prediction.
model.json
{"modelTopology":{"class_name":"Sequential","config":[{"class_name":"Flatten","config":{"name":"flatten_Flatten1","trainable":true,"batch_input_shape":[null,7,7,256],"dtype":"float32"}},{"class_name":"Dense","config":{"units":100,"activation":"relu","use_bias":true,"kernel_initializer":{"class_name":"VarianceScaling","config":{"scale":1,"mode":null,"distribution":null,"seed":null}},"bias_initializer":{"class_name":"Zeros","config":{}},"kernel_regularizer":null,"bias_regularizer":null,"activity_regularizer":null,"kernel_constraint":null,"bias_constraint":null,"name":"dense_Dense1","trainable":true}},{"class_name":"Dense","config":{"units":3,"activation":"softmax","use_bias":false,"kernel_initializer":{"class_name":"VarianceScaling","config":{"scale":1,"mode":null,"distribution":null,"seed":null}},"bias_initializer":{"class_name":"Zeros","config":{}},"kernel_regularizer":null,"bias_regularizer":null,"activity_regularizer":null,"kernel_constraint":null,"bias_constraint":null,"name":"dense_Dense2","trainable":true}}],"keras_version":"tfjs-layers 0.7.0","backend":"tensor_flow.js"},"weightsManifest":[{"paths":["./ml-classifier-1-2-3.weights.bin"],"weights":[{"name":"dense_Dense1/kernel","shape":[12544,100],"dtype":"float32"},{"name":"dense_Dense1/bias","shape":[100],"dtype":"float32"},{"name":"dense_Dense2/kernel","shape":[100,3],"dtype":"float32"}]}]}
index.js
var tf = require('@tensorflow/tfjs-node');
const image = `./1-1.png`
const main = async () => {
const model = await tf.loadLayersModel('file:///retake/savedmodels/model.json');
model.summary();
const prediction = model.predict(image);
prediction.print();
}
main()