nsfwspy / nsfwspy.js Goto Github PK
View Code? Open in Web Editor NEWA JavaScript image classifier used to identify explicit/pornographic content written in TypeScript.
License: MIT License
A JavaScript image classifier used to identify explicit/pornographic content written in TypeScript.
License: MIT License
Hi, i am Subhan Attique from FAST National University in Pakistan. I am making a chrome extension in MERN framework that should be able to block explicit or violent content on the web browser, i found this package and i thought that i could use it for the EXPLICIT part. Now i think i am doing everything right. I have download all of the file that you provided along with your model. I gave the path to model as specified in README file. But my extension is not fetching it up, Giving error -- TypeError: Failed to fetch. It is more of a confusion than issue that is this package compatible in webpack or manifest file for extensions. If yes, then kindly let me know. Thank you.
const NSFWNET_WEIGHTS_PATH ='models/model.json';
const IMAGE_SIZE = 224;
const IMAGE_CROP_SIZE = 224;
const TOPK_PREDICTIONS = 4;
const NSFW_CLASSES = {
0: 'Hentai',
1: 'Neural',
2: 'Porn',
3: 'Sexy',
};
let nsfwnet;
const nsfwnetDemo = async () => {
nsfwnet = await tf.loadGraphModel(NSFWNET_WEIGHTS_PATH);
nsfwnet.predict(tf.zeros([1, IMAGE_CROP_SIZE, IMAGE_CROP_SIZE, 3])).dispose();
console.log('Model Warm complete');
const image_Element = document.getElementById('test_draw');
if (image_Element.complete && image_Element.naturalHeight !== 0) {
predict(image_Element);
image_Element.style.display = '';
}
document.getElementById('file-container').style.display = '';
};
async function predict(imgElement) {
const logits = tf.tidy(() => {
const img = tf.browser.fromPixels(imgElement).toFloat();
const crop_image = tf.slice(img, [16, 16, 0], [224, 224, -1]);
const img_reshape = tf.reverse(crop_image, [-1]);
let imagenet_mean = tf.expandDims([103.94, 116.78, 123.68], 0);
imagenet_mean = tf.expandDims(imagenet_mean, 0);
const normalized = img_reshape.sub(imagenet_mean);
const batched = normalized.reshape([1, IMAGE_CROP_SIZE, IMAGE_CROP_SIZE, 3]);
return nsfwnet.predict(batched);
});
const classes = await getTopKClasses(logits, TOPK_PREDICTIONS);
display(classes);
}
async function getTopKClasses(logits, topK){
const values = await logits.data();
sortArray = Array.from(values).map((value, index) => {
return {
value: value,
index: index
};
}
).sort((a, b) => {
return b.value - a.value;
}).slice(0, topK);
return sortArray.map(x => {
return {
className: NSFW_CLASSES[x.index],
probability: x.value
};
}
);
}
function display(classes){
console.log(classes);
}
nsfwnetDemo();
$ node .
2023-07-09 16:20:01.450460: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
\node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:30397
this.version = graph.versions.producer + "." + graph.versions.minConsumer;
^
TypeError: Cannot read properties of undefined (reading 'producer')
at GraphModel.loadSync (\node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:30397:39)
at \node_modules\@tensorflow\tfjs-converter\dist\tf-converter.node.js:30373:72
Node.js v18.14.2
Background:
I'm currently working on developing a model to tackle a specific problem and I'm in need of a relevant dataset to train and evaluate the model effectively.
Data Usage:
The dataset will solely be used for research and development purposes. It will not be redistributed or used for commercial purposes. Proper attribution and credit will be given to the dataset source in any publications or releases related to the trained model.
Request:
I kindly request access to a suitable dataset that is used or can be used to train new model. If you or your organization have access to such a dataset or can provide guidance on where I might find one, I would greatly appreciate it.
Note:
Please feel free to reach out to me if you have any questions, need further clarification, or require additional information.
I looked at the results section: https://github.com/NsfwSpy/NsfwSpy.js#results
In my testing of NSFWJS (Inception v3), it performs better than NSFWSpy in nearly all images I tested. Can you specify the images you used in your comparison testing, as well as which NSFWJS model you used? (Inception v3 vs MobileNet v2)
One example:
NSFWJS: https://i.imgur.com/tNJjWKF.png
NSFWSpy: https://i.imgur.com/0XP0WAl.png
Second example:
NSFWJS: https://i.imgur.com/TXCybfO.png
NSFWSpy: https://i.imgur.com/EBydbEL.png
The images are definitely not used in any of your or NSFWJS's training, so they are fresh images for the AI so there's no that it's biased based on that.
Second question:
Can you specify what training data you used? Not every image, but what sources you used, for example, which subreddits, porn websites, categories, etc. I saw the listing of the files per classification, but I think specifying more granular data would be more useful, especially when retraining.
I'm trying to run this as a node.js module. I cloned your project, moved into the NsfwSpy-node directory and created my project. I load the model that is in ../models/mobilenet-v1.0.0/model.json
and I get the following error
This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
I don't think there is anything wrong with my code so far because it's just trying to run the example that you have in the Readme.md but my code is as follows
const nsfwSpy = new NsfwSpy("../models/mobilenet-v1.0.0/model.json");
const filePath = "/home/fmx/Pictures/Screenshot_20230528_120040.png";
await nsfwSpy.load();
const result = await nsfwSpy.classifyImageFile(filePath);
console.log("Console Log!!")
console.log(result);```
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.