Reputation: 3
I was trying to load the face-api.js models in an Nextjs app but keep getting the error
Unhandled Runtime Error Error: Failed to parse URL from /model/ssd_mobilenetv1_model-weights_manifest.json
This is weird cause it happends on Nextjs only while i dont have any problems on a normal nodejs app.
code:
import * as faceapi from 'face-api.js';
import fs from 'fs';
export async function loadingModels() {
const exists = fs.existsSync('public/model/tiny_face_detector_model-weights_manifest.json');
console.log(exists)
await faceapi.nets.ssdMobilenetv1.load('/model')
}
I thought that its because i placed my models in the wrong place but i checked and it is there. It just wont load :((
Upvotes: 0
Views: 768
Reputation: 865
--
export async function loadingModels() {
const modelPath = process.env.NEXT_PUBLIC_BASE_PATH || '';
const modelUrl = `${modelPath}/model`;
// Load the models
await faceapi.nets.ssdMobilenetv1.loadFromUri(modelUrl);
}
In .env file, add below line.
NEXT_PUBLIC_BASE_PATH = http://localhost:3000/
Updated:
Try to import the file .
Upvotes: 0