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

Which model is the best atm? Resources hardware is not a problem. inception_v4? #777

Open
FurkanGozukara opened this issue Aug 13, 2023 · 0 comments

Comments

@FurkanGozukara
Copy link

I see https://tfhub.dev/tensorflow/lite-model/inception_v4/1/default/1

Is that best one?

or this one best? https://tfhub.dev/google/imagenet/inception_v3/classification/5

I need a local app to classify all images

Here my code

const fs = require('fs');
const tf = require('@tensorflow/tfjs-node');
const nsfwjs = require('nsfwjs');

async function classifyImageWithInceptionV3(imagePath) {
  const imageBuffer = fs.readFileSync(imagePath);
  const image = tf.node.decodeImage(imageBuffer);
  
  // Load InceptionV3 model from TensorFlow.js
  const inceptionV3 = await tf.loadLayersModel('https://tfhub.dev/google/imagenet/inception_v3/classification/5');
  const processedImage = tf.image.resizeBilinear(image, [299, 299]).toFloat().div(255.0).expandDims();

  const predictions = await inceptionV3.predict(processedImage).data();
  return predictions;
}

function moveImage(imagePath, category) {
  const destinationFolder = `./${category}`;
  fs.renameSync(imagePath, `${destinationFolder}/${imagePath}`);
}

async function scanImages(inputFolder) {
  const imageFiles = fs.readdirSync(inputFolder);

  for (const imageFile of imageFiles) {
    const imagePath = `${inputFolder}/${imageFile}`;
    const predictions = await classifyImageWithInceptionV3(imagePath);

    const maxProbability = Math.max(...predictions);
    const maxIndex = predictions.indexOf(maxProbability);

    // Move to the folder with the highest probability
    const categories = ['Drawing', 'Hentai', 'Porn', 'Sexy'];
    moveImage(imagePath, categories[maxIndex]);
  }
}

const inputFolder = './input'; // Replace with your input folder path
scanImages(inputFolder);


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

1 participant