Click here to Skip to main content
15,908,166 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am using faceapi-js for face recognition, but when I used other PCs to run the webpage, it will return the error:

https://www.sample.com/face_recognition/final/models/tiny_face_detector_model-weights_manifest.json' from origin 'https://sample.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. face-api.min.js:1 GET https://www.sample.com/face_recognition/final/models/tiny_face_detector_model-weights_manifest.json net::ERR_FAILED

This is the code to load the models:
Promise.all([
    faceapi.nets.tinyFaceDetector.loadFromUri('https://www.sample.com/face_recognition/final/models'),
    faceapi.nets.faceLandmark68Net.loadFromUri('https://www.sample.com/face_recognition/final/models'),
    faceapi.nets.faceRecognitionNet.loadFromUri('https://www.sample.com/face_recognition/final/models'),
    faceapi.nets.ssdMobilenetv1.loadFromUri('https://www.sample.com/face_recognition/final/models')
  ]).then(StartVideo).then(GetLabels);

Note: I have to change the url as it is used for a project.

What I have tried:

I can run it on my other machine, but there seems to be issues with this machine.
Posted
Updated 12-Apr-21 15:10pm

The site you are trying to load the scripts from is not configured to allow your site to load the scripts.

Cross-Origin Resource Sharing (CORS) - HTTP | MDN[^]

There is nothing you can do to fix this without the cooperation of the people who run the site you're trying to load the scripts from.
 
Share this answer
 
I changed the code to load the models into a relative path.
Promise.all([
    faceapi.nets.tinyFaceDetector.loadFromUri('./models'),
    faceapi.nets.faceLandmark68Net.loadFromUri('./models'),
    faceapi.nets.faceRecognitionNet.loadFromUri('./models'),
    faceapi.nets.ssdMobilenetv1.loadFromUri('./models')
  ]).then(StartVideo).then(GetLabels);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900