TFJS error with MobileNetV2

I am trying to use Tensorflow JS with the Cifar 10 dataset. But I am constantly getting the following error.

tfjs:17 Uncaught (in promise) Error: Argument ‘images’ passed to ‘resizeBilinear’ must be a Tensor or TensorLike, but got ‘e’

Here is my code

async function getModel() {
    const NUM_OUTPUT_CLASSES = 10;

    // Load the MobileNetV2 model from TensorFlow Hub
    const mobilenetModel = await tf.loadGraphModel(
        "https://tfhub.dev/google/tfjs-model/imagenet/mobilenet_v2_035_224/classification/3/default/1",
        { fromTFHub: true }
    );

    console.log(mobilenetModel); // Check the loaded model
    console.log('Inputs:', mobilenetModel.inputs); // Log the model inputs
    console.log('Outputs:', mobilenetModel.outputs); // Log the model outputs

    // Assuming inputs and outputs are valid, proceed with the model construction
    if (!mobilenetModel.inputs || mobilenetModel.inputs.length === 0) {
        throw new Error('Model inputs are undefined or empty.');
    }

    const input = mobilenetModel.inputs[0]; // Get the first input tensor
    const mobilenetOutput = mobilenetModel.outputs[0]; // Get the output tensor from MobileNetV2

    // Flatten the output from MobileNetV2
    const flatten = tf.layers.flatten().apply(mobilenetOutput);

    // Add a dense layer for further processing
    const dense1 = tf.layers.dense({
        units: 128,
        activation: 'relu',
        kernelInitializer: 'varianceScaling'
    }).apply(flatten);

    // Add the final dense layer with softmax activation for classification
    const output = tf.layers.dense({
        units: NUM_OUTPUT_CLASSES,
        activation: 'softmax'
    }).apply(dense1);

    // Create the final model
    const finalModel = tf.model({
        inputs: input,
        outputs: output
    });

    // Compile the model
    finalModel.compile({
        optimizer: tf.train.adam(),
        loss: 'categoricalCrossentropy',
        metrics: ['accuracy'],
    });

    return finalModel;
}

Hi @Fahim_Arsad_Nafis ,

I apologize for the delay in my response. The resizeBilinear function isn’t used in your provided code. To help troubleshoot the error, could you please share a minimal code snippet that reproduces the issue?

The resizeBilinear function expects the first parameter to be an image tensor in the format of a tf.Tensor3D, tf.Tensor4D, TypedArray, or Array. The error suggests it might not be receiving an image tensor. You can check the data type of the input you’re providing to resizeBilinear.

Let me know if it helps. Thank You!!