Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Could not load the model. Make sure you are importing the model.min.js bundle. #863

Closed
ChrisBechi opened this issue Jun 13, 2024 · 5 comments · Fixed by #897
Closed

Comments

@ChrisBechi
Copy link

ChrisBechi commented Jun 13, 2024

I have a Vite project and I'm getting the following error when installing the library in version: ^4.1.0. I followed the documentation but apparently Vite has some issues. Does anyone know how I can solve this?

nsfwjs.js?v=168f040f:67180 Uncaught (in promise)
Error: Could not load the model. Make sure you are importing the model.min.js bundle.
at nsfwjs.js?v=168f040f:67180:17
at step4 (nsfwjs.js?v=168f040f:67073:18)
at Object.next (nsfwjs.js?v=168f040f:67025:14)
at nsfwjs.js?v=168f040f:67012:70
at new Promise ()
at __awaiter (nsfwjs.js?v=168f040f:66994:10)
at loadModel (nsfwjs.js?v=168f040f:67158:10)
at Module. (nsfwjs.js?v=168f040f:67212:22)
at step4 (nsfwjs.js?v=168f040f:67073:18)
at Object.next (nsfwjs.js?v=168f040f:67025:14)

@Anas-7
Copy link

Anas-7 commented Jul 16, 2024

Hi, did you find a fix for this? Currently facing the same issue

@liuyudaye
Copy link

When will this problem be fixed? I've encountered it too.

@stevecohenfr
Copy link

Same here with a Ionic/Angular project (only on production)

@atheless
Copy link

atheless commented Sep 28, 2024

I am having the same issue in my Nuxt 3 (with spa mode) project. It throws an error right after this line: const model = await nsfwjs.load("MobileNetV2Mid"); with the following imports from docs

import * as tf from "@tensorflow/tfjs";
import * as nsfwjs from "nsfwjs";

Any solutions?

nsfwjs.js?v=0f6cacb3:217 Uncaught (in promise) Error: Could not load the model. Make sure you are importing the model.min.js bundle.
    at nsfwjs.js?v=0f6cacb3:217:17
    at step (nsfwjs.js?v=0f6cacb3:110:17)
    at Object.next (nsfwjs.js?v=0f6cacb3:62:14)
    at nsfwjs.js?v=0f6cacb3:49:67
    at new Promise (<anonymous>)
    at __awaiter (nsfwjs.js?v=0f6cacb3:31:10)
    at loadModel (nsfwjs.js?v=0f6cacb3:195:10)
    at Module.<anonymous> (nsfwjs.js?v=0f6cacb3:249:22)
    at step (nsfwjs.js?v=0f6cacb3:110:17)
    at Object.next (nsfwjs.js?v=0f6cacb3:62:14)

@atheless
Copy link

atheless commented Sep 29, 2024

Found a solution to my problem.

Instead of this as per docs:

const model = nsfwjs.load("/nsfw_models/inception_v3/", { type: "graph" });

Use this one:

 const model = await nsfwjs.load("/nsfw_models/inception_v3/", { size: 299 });

Same thing for MobileNetV2Mid but with { type: "graph" }. In fact options in source code appear differently compared to docs.

const availableModels: ModelConfig = {
  MobileNetV2: { path: "mobilenet_v2", numOfWeightBundles: 1 },
  MobileNetV2Mid: {
    path: "mobilenet_v2_mid",
    numOfWeightBundles: 2,
    options: { type: "graph" },
  },
  InceptionV3: {
    path: "inception_v3",
    numOfWeightBundles: 6,
    options: { size: 299 },
  },
};

If you are running a bundling issues with vite, just download src folder and save it locally, and import it like this:

import * as nsfwjs from "@/utils/nsfwjs" // nsfwjs contain .ts and .js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants