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

Need help with model.classifyGif() #436

Closed
edsumpena opened this issue Nov 9, 2020 · 6 comments
Closed

Need help with model.classifyGif() #436

edsumpena opened this issue Nov 9, 2020 · 6 comments
Labels
Node.js question Further information is requested

Comments

@edsumpena
Copy link

edsumpena commented Nov 9, 2020

Hi, I'm building a server on node.js to handle NSFW gifs. However, I've run into some error messages and I'm not sure how to resolve them.

(node:4365) UnhandledPromiseRejectionWarning: Error: "url" option is required.
at Object.gifFrames [as default] (/home/runner/HandmadeSeparateProjections/node_modules/@nsfw-filter/gif-frames/gif-frames.js:45:12)
at NSFWJS. (/home/runner/HandmadeSeparateProjections/node_modules/nsfwjs/dist/index.js:204:60)
at step (/home/runner/HandmadeSeparateProjections/node_modules/nsfwjs/dist/index.js:52:23)
at Object.next (/home/runner/HandmadeSeparateProjections/node_modules/nsfwjs/dist/index.js:33:53)
at /home/runner/HandmadeSeparateProjections/node_modules/nsfwjs/dist/index.js:27:71
at new Promise ()
at __awaiter (/home/runner/HandmadeSeparateProjections/node_modules/nsfwjs/dist/index.js:23:12)
at NSFWJS.classifyGif (/home/runner/HandmadeSeparateProjections/node_modules/nsfwjs/dist/index.js:193:16)
at Client. (/home/runner/HandmadeSeparateProjections/index.js:1800:38)

So here's what I have done:

const pic = await axios.get(linkToGif, {
              responseType: 'arraybuffer',
})     // Get the GIF in the form of a buffer (encoded in uint8)

const image = await tf.node.decodeGif(pic.data)     //Decode the GIF using tensorflow

const prediction = await model.classifyGif(image);     //Classify the GIF (This is where the error is thrown)

Can anyone please help me out? Is there anywhere I can find sample code to GIF classification? Thank you in advance.

@GantMan GantMan added question Further information is requested Node.js labels Nov 9, 2020
@GantMan
Copy link
Member

GantMan commented Nov 9, 2020

Pinging @YegorZaremba - But I'll see about taking a look next week if he doesn't get a chance to look at this.

I should def include a node sample for gifs in the examples folder.

@edsumpena
Copy link
Author

That sounds great. Thank you for your quick response!

@yzevm
Copy link
Contributor

yzevm commented Nov 10, 2020

Hi @edsumpena Here is test for classifyGif /~https://github.com/infinitered/nsfwjs/blob/master/__tests__/classifyGif.ts#L43

According to error /~https://github.com/nsfw-filter/gif-frames/blob/master/gif-frames.js#L45, It looks like your url: gif is empty /~https://github.com/infinitered/nsfwjs/blob/master/src/index.ts#L208

could you pls write result of this for me

const image = await tf.node.decodeGif(pic.data)  
console.log(Buffer.isBuffer(image))

Related: #431

@edsumpena
Copy link
Author

edsumpena commented Nov 10, 2020

Hi @YegorZaremba, I have run the log command. It returns "false". I'm assuming that it should return "true"?

@yzevm
Copy link
Contributor

yzevm commented Nov 10, 2020

@edsumpena I think you should skip decoding gif by tenserflow and pass buffer as is. We will improve this step for Node.js #431 (comment)

This code also runs in browsers. Browsers don't have some Node.js stuff. I plan to do separate logic in this lib for browsers and Node.js in the future

@edsumpena
Copy link
Author

I have run the code without tf.node.decodeGif(pic.data) and it works. Thank you for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Node.js question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants