nsfwjs icon indicating copy to clipboard operation
nsfwjs copied to clipboard

[Question] Nodejs server side prediction

Open chia7 opened this issue 4 years ago • 12 comments

Hi, is there a way to perform prediction on server side with nodejs, without converting the local image as in the demo code? I would like to directly use fs to read my local file and pass it into the model, is it possible? I supposed that this would largely improve the performance and reduce the running time.

chia7 avatar Mar 18 '21 12:03 chia7

I think images have to be converted to a tensor before they can be evaluated against the model.

kevinvangelder avatar Mar 18 '21 16:03 kevinvangelder

Got it! Would it be better to use jpeg over png for prediction? Or any other image format you may suggest?

chia7 avatar Mar 22 '21 02:03 chia7

The fastest way to do this conversion would be to use the TFJS node lib. I haven't updated the demo code bc of time restrictions, but I am releasing a book where I explain how to do this quite clearly:

https://amzn.to/3dR3vpY

GantMan avatar Mar 22 '21 15:03 GantMan

I have the same question : I'd like to perform a prediction on serverside with nodejs (firebase cloud functions).

Is there anyway to do that with this package or is it not possible at all ?

Kamel38 avatar Mar 23 '21 09:03 Kamel38

It is completely possible.

I guess I could improve the docs here. But it would be awesome if someone contributed the change.

I explain NodeJS image to tensor directly in my book. But if no one can do it, I can see about setting aside some time at some point.

GantMan avatar Mar 24 '21 15:03 GantMan

@kevinvangelder let me know if this is something you'd like to do. I will, of course, help.

GantMan avatar Mar 24 '21 15:03 GantMan

hi, bumping this :) I recently discovered this module and I'm interested to use it server-side

justekoro avatar Jul 09 '21 22:07 justekoro

Sorry Korobaka, I'll have to find some time and add to the docs. I'll try to find some time this weekend.

GantMan avatar Aug 05 '21 02:08 GantMan

Sorry Korobaka, I'll have to find some time and add to the docs. I'll try to find some time this weekend.

np! take your time :)

justekoro avatar Aug 05 '21 12:08 justekoro

Hey all, we're working on this!

Our proof of concept: https://github.com/ipfs-search/nsfw-server

Mad props for NSFW.js!

dokterbob avatar Jan 27 '22 21:01 dokterbob

very cook @dokterbob - I'm planning on adding a voting classifier on top of NSFWJS that will make you able to reallllllly dial in the accuracy vs type 1 and type 2 errors. It should help increase accuracy!

GantMan avatar Jan 27 '22 22:01 GantMan

Also, let me know when you're ready for me to promote NSFW-server on socails!

GantMan avatar Jan 27 '22 22:01 GantMan