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

classifyGif() - server side #305

Open
ghnp5 opened this issue Apr 19, 2020 · 2 comments
Open

classifyGif() - server side #305

ghnp5 opened this issue Apr 19, 2020 · 2 comments

Comments

@ghnp5
Copy link

ghnp5 commented Apr 19, 2020

Hello,

Thank you very much for implementing NSFWJS, which works very well!

I use this as a Node.JS microservice app, doing Server-Side validation of photos uploaded to my website.

Works well for JPG images. The Node app retrieves an image from a URL, converts to buffer, runs tf.tensor3d(), then classify().

However, I am not sure how to classify GIF images, server side.
From looking at your code, it appears that the "gif" parameter must be a DOM img element.

Is it possible to classify GIF images server side?

I suppose I can manually go through every frame of the GIF and run classify(), but if this could be natively implemented in NSFWJS, that would be perfect!

Have a great day. Thank you.

@GantMan
Copy link
Member

GantMan commented Apr 20, 2020

I haven't run into the need to do this server-side just yet. I'd love to get a pull-request and merge the code so NSFWJS does this, would you be willing to solve it and send the code?

@ghnp5
Copy link
Author

ghnp5 commented Apr 20, 2020

Unfortunately, I won't have the time to do a PR, but this is the way I got around it myself, using gifFrames:

		gifFrames({
			url: dataBuffer,
			frames: 'all',
			outputType: 'jpg',
			cumulative: true
		},
		async (err, frameData) => {
			if (err) {
				throw err;
			}
			frameData.forEach(function (frame) {
				const jpgStream = frame.getImage();
				... convert and classify, and add to an array
			});
		});

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

No branches or pull requests

2 participants