nsfwjs
nsfwjs copied to clipboard
Cannot load latest (v1.1) nsfw_model from local file
I currently have the latest nsfw_model found at https://github.com/GantMan/nsfw_model/releases/tag/1.1.0 and am trying to load it as a local file like so:
const model = await nsfw.load('file://' + __dirname + '/mobilenet_v2_140_224/web_model_quantized/');
However this results in the following error:
(node:28129) UnhandledPromiseRejectionWarning: Error: layer: Improper config format: (LARGE JSON OBJECT HERE).
'className' and 'config' must set.
I tried the solution found in #397, specifically this comment, however when running npm install @tensorflow/tfjs@^1.7.4
I get:
npm ERR!
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: @tensorflow/[email protected]
npm ERR! node_modules/@tensorflow/tfjs
npm ERR! @tensorflow/tfjs@"^1.7.4" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @tensorflow/tfjs@"^3.1.0" from [email protected]
npm ERR! node_modules/nsfwjs
npm ERR! nsfwjs@"^2.4.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/jon/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/jon/.npm/_logs/2021-05-07T15_30_17_117Z-debug.logcode ERESOLVE
Running npm install @tensorflow/tfjs@^1.7.4 --force
works to install that version but then the load
function fails to load a local file, saying only absolute URLs are supported
@tensorflow/tfjs-node: ^3.6.1 nsfwjs: ^2.4.0
Thanks for the detailed ticket. Can you make a small demo-repo and I'll pull that down and debug the issue? That's he most effective way for me to construct a fix
I seem to have found the issue while making the demo repo (which honestly was only going to be like 3 lines of code)
I was following the "NodeJS App" example here https://github.com/infinitered/nsfwjs#node-js-app which only says to pass in the path to the model folder
However with the latest nsfw_model it seems to need you to pass in { type: 'graph' }
into the options? This seems to have loaded the model correctly and it does seem to classify correctly still
Maybe this should be better explained in the README and examples? It wasn't immediately obvious that I needed to pass in this option to get the local files to work, especially since when looking at the source of this module it doesn't pass that option...?
Ahhh, which model are you using? The 93% accurate one?
Please feel free to contribute back to the docs. It's easy to forget to update them, and your experience from the outside is valuable to others who come in and use the docs.
I seem to have found the issue while making the demo repo (which honestly was only going to be like 3 lines of code)
I was following the "NodeJS App" example here https://github.com/infinitered/nsfwjs#node-js-app which only says to pass in the path to the model folder
However with the latest nsfw_model it seems to need you to pass in
{ type: 'graph' }
into the options? This seems to have loaded the model correctly and it does seem to classify correctly stillMaybe this should be better explained in the README and examples? It wasn't immediately obvious that I needed to pass in this option to get the local files to work, especially since when looking at the source of this module it doesn't pass that option...?
Hi RedDuck, I tried the following:
_model = await nsfw.load('.\models\2020-03-04 - nsfw_mobilenet_v2_140_224\mobilenet_v2_140_224\web_model', "{ type: 'graph' }")
But I get this error:
Cannot create property 'size' on string '{ type: 'graph' }'
How did you pass in the { type: 'graph' }
option?
Thanks, Fidel
Oh, never mind :) This worked:
_model = await nsfw.load('file://' + __dirname + '/models/2020-03-04 - nsfw_mobilenet_v2_140_224/mobilenet_v2_140_224/web_model/', { type: 'graph', })
Please feel free to contribute back to the docs. It's easy to forget to update them, and your experience from the outside is valuable to others who come in and use the docs.
Sure, I can do that. How would the best way to do that be? Just make a PR for the readme to add { type: 'graph' }
?
Yup! And any additional context.
Just checking in on this ticket.