reactjs – Error Loading face-api.js Fashions: Tensor Form Mismatch on iOS App with React and Capacitor

0
28
reactjs – Error Loading face-api.js Fashions: Tensor Form Mismatch on iOS App with React and Capacitor


I’m constructing an iOS app utilizing React and Capacitor that makes use of face-api.js for facial recognition. The app runs nice in an internet atmosphere each regionally and on prod for each home windows and IOS. Nonetheless, I encounter points when loading the face-api.js fashions on xcode in growth mode. Particularly, I’m getting a tensor form mismatch error that I can not seem to resolve.

Error:

This error happens as quickly because the fashions are loaded, even earlier than I try to make use of them for scanning faces. Right here’s the total error message:

Error loading face-api.js fashions:
Error: Based mostly on the offered form, [1,1,512,9], the tensor ought to have 4608 values however has 1324
    at lt — util.ts:108
    at $r — tensor_ops.ts:87
    at o — io_utils.ts:175
    at Yd — io_utils.ts:116
    ...
    at AddEmployeePage.js:38

What I’ve Tried:

1- Mannequin Loading Code:

I’m utilizing the next code to load fashions from a CDN. This works completely on the internet and android apps, however throws the error above on iOS.

const loadModels = async () => {
    strive {
        const modelUrl = "https://cdn.jsdelivr.internet/gh/justadudewhohacks/[email protected]/weights";
        await faceapi.nets.ssdMobilenetv1.loadFromUri(modelUrl);
        await faceapi.nets.faceRecognitionNet.loadFromUri(modelUrl);
        await faceapi.nets.faceLandmark68Net.loadFromUri(modelUrl);
        console.log("Fashions loaded efficiently");
    } catch (err) {
        console.error("Error loading face-api.js fashions:", err.message);
    }
};

2- Loading from Native Recordsdata:

I’ve tried loading fashions from the app’s native filesystem, however the identical challenge persists. I ensured that each one mannequin recordsdata are accurately positioned and accessible.

3- Various Loading Strategies:

I additionally tried to load fashions by way of an offline CDN with no distinction in end result.

Further Info:

Setting:

  • React (with Capacitor for native iOS construct)

  • face-api.js model: 0.22.2

  • Hosted the net model efficiently on Vercel.

Goal:

I would like the facial recognition to operate offline in addition to in net environments. The app might be deployed on a number of iOS gadgets and should deal with real-time facial recognition effectively.

If in case you have any questions for me, please do not hesitate to ask!

Any insights or workarounds could be significantly appreciated!

LEAVE A REPLY

Please enter your comment!
Please enter your name here