Giter Club home page Giter Club logo

tasnif's Introduction

accessibility text

Tasnif is a Python package designed for clustering images into user-defined classes based on their visual content. It utilizes deep learning to generate image embeddings, Principal Component Analysis (PCA) for dimensionality reduction, and K-means for clustering. Tasnif supports processing on both GPU and CPU, making it versatile for different computational environments.

Features

  • Generate embeddings for images using a pre-trained model.
  • Dimensionality reduction using PCA to enhance clustering performance.
  • Clustering of images into user-specified classes with K-means.
  • Visualization support by creating image grids for each cluster.
  • Efficient image reading and preprocessing utilities.

Installation

To install Tasnif, you need Python 3.6 or later. Clone this repository to your local machine and install the required dependencies:

pip install tasnif

Usage

Import Tasnif and initialize it with the desired number of classes, PCA dimensions, and whether to use GPU:

from tasnif import Tasnif

# Initialize Tasnif with 5 classes, PCA dimensions set to 16, and GPU usage
classifier = Tasnif(num_classes=5, pca_dim=16, use_gpu=False)

Read the images from a directory, calculate the embeddings, PCA, and perform K-means clustering:

# Read images from a specified directory
classifier.read('path/to/your/images')

# Calculate embeddings, PCA, and perform clustering
classifier.calculate()

Finally, export the clustered images and visualization grids to a specified directory:

# Export clustered images and grids
classifier.export('path/to/output')

To-Do

  • Prevent calculation if there is no image read (PCA & k-means)
  • Export embeddings
  • Make model independent from img2vec
  • Separate cpu and gpu installation and catch gpu errors

Contributing

Contributions to Tasnif are welcome! Please fork the repository and submit a pull request with your proposed changes.

Contributors

License

Tasnif is released under the MIT License. See the LICENSE file for more details.

tasnif's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tasnif's Issues

[Feature Request] Getting Embeddings For Facial Images with Facial Recognition Models

Thank you for the project!

As I see, you are using pytorch's img2vec to generate embeddings. As an alternative, we may consider checking a face is available in the image, and if yes find its embeddings with a facial recognition model such as FaceNet.

# !pip instal deepface
from deepface import DeepFace

# check face is available in the given image. img can be a file on the filesystem, or numpy array as well.
face_objs = DeepFace.extract_faces(img_path = img, detector_backend="mtcnn")

if faces:
   for face_obj in face_objs 
      detected_face = face_obj["face"]
      embedding = DeepFace.represent(img_path = detected_face, model_name="Facenet", detector_backend="skip")
else:
   # continue to do with pytorch's img2vec

I will be happy to contribute if this attracts your attention. Feel free to close this ticket if you think this will cause losing its way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.