infinitered / nsfwjs

NSFW detection on the client-side via TensorFlow.js
https://nsfwjs.com/
MIT License
8.13k stars 547 forks source link

Extreme CPU usage with nodejs #633

Open ThatKoffe opened 2 years ago

ThatKoffe commented 2 years ago

Whilest going through an image my server goes up to ^500%

Is there any way to optimize this?

image

Any advice would be appreciated!

// This code is ran in the backend.
import * as nsfw from 'nsfwjs';

const model = await nsfw.load();
const image = await tf.node.decodeImage(pic.data, 3); // pic is from an axios request.
const predictions = await model.classify(image);
image.dispose();

I am using ts-node for if that's relevant.

GantMan commented 2 years ago

WOW! That's wild. I've never seen this. I'll do some testing.

ThatKoffe commented 2 years ago

Thank you @GantMan , my use case is nsfw image detection (auto-moderation) for a platform i am making - Hope that it helps

FurkanGozukara commented 1 year ago

hi can you share example code to locally classify images by loading locally best model? thank you