Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The shape of dict['ToFloat'] provided in model.execute(dict) must be []

enter image description here

** I'M AWARE OF SIMILAR QUESTIONS!! **

My question is for my particular situation... I used Google Vision to train my own model to detect custom objects. I've come across similar errors about shape in the past and I resolved them by reshaping my input image.

This particular error is telling me that my shape must be an empty array or empty shape. Is that even possible? If this is not a glitch, how do i resolve it?

This is how I resolved previous errors in other projects when it complains about shape. This solution does not work for empty array/shape

    const model = await autoML.loadObjectDetection('./model/model.json');
 // const model = await tfjs.loadGraphModel('./model/model.json');
    await tfjs.ready();
    const tfImg = tfjs.browser.fromPixels(videoElement.current).expandDims(0);
    const smallImg = await tfjs.image.resizeBilinear(tfImg, [224, 224]);
    const resized = tfjs.cast(smallImg, 'float32');
    const t4d = tfjs.tensor4d(Array.from(resized.dataSync()), [1, 224, 224, 3]);
    const predictions = await modelRef.current.detect(tfImg, options);
like image 843
TonyCruze Avatar asked Nov 06 '22 05:11

TonyCruze


1 Answers

I had the same problem with my tfjs models from Vision AI when I exported them to tfjs models and followed this article to load the model.

Workaround:

As a workaround I exported the model from Vision AI to the SavedModel format and converted it to tfjs model with tensorflow_converter following this guide. The result can be loaded as expected and works fine.

like image 107
Vale Avatar answered Nov 15 '22 11:11

Vale