Skip to main content

A python library for image classification using ML techniques

Project description

mlclassifier is a package with custom algorithms to classify data using ml. It currently only supports image classification.

To install it, use pip install mlclassifier.

To classify images, you must have a dataset for the images with this folder structure

dataset_folder/
├── class1/
│   ├── image1.jpg
│   ├── image2.jpg
│   └── ...
└── class2/
    ├── image1.jpg
    ├── image2.jpg
    └── ...

The image names or class names don't matter. The classifier assigns a class number in the order of classes from top to bottom.

To classify images, you first need to train the model using ImageClassifierTrainer.

from mlclassifier import ImageClassifierTrainer # import the trainer
import mlclassifier # import the package

trainer = ImageClassifierTrainer("<the_path_to_your_dataset", method=mlclassifier.PICK_BEST,  # Create the ImageClassiferTrainerObject
                                 resize_size=(128, 128), model_path="<path_you_want_to_save_the_model>",
                                 n_runs=5) 

trainer.fit() # train the model

The method parameter is used to specify which feature extraction method to use. You can use HOG (mlclassifier.HOG), or ORB (mlclassifier.ORB), or LBP (mlclassifier.LBP), or you can make it run all 3 and save the best one using mlclassifier.PICK_BEST.

The resize_size parameter is the size you want to resize all the images to for consistency

The n_runs parameter is used to set the number of times you want to train the classifier. It will pick the best trained one out of all the runs and save it.

The model_path parameter must be a .pkl file.

At the end of the training cycle, it will print the Average FPS if you were to stream images to it, the time it took per image, and the score.

After training, you can start classifying images using ImageClassifier.

from mlclassifier import ImageClassifier # import the ImageClassifier 
import cv2 # import cv2

classifier = ImageClassifier("<model_path>") # create the classifier object
image = cv2.imread("<path_to_your_image") # read the image

predicted_class = classifier.predict(image) # predict the class

print(predicted_class) # print the predicted class

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlclassifier-1.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlclassifier-1.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file mlclassifier-1.1.0.tar.gz.

File metadata

  • Download URL: mlclassifier-1.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for mlclassifier-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7f0d1412ca4f1b71be827f32ad3f9fe231efbf4e93ab4e1036e6b9b559db736f
MD5 24731bca0cbceeb75b7830fffbe3fd62
BLAKE2b-256 1125fae18cf30c71d9e22c6c52d8b21e705817631129f56e546794048a9c1946

See more details on using hashes here.

File details

Details for the file mlclassifier-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: mlclassifier-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for mlclassifier-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ed82295f58a88827dcfcecf333d1ffd5ece021d7ef056c070868c908f12b68
MD5 b4f7d2b1c32ce53bcba87974077f7101
BLAKE2b-256 b236f91a8ab6bb3864d0474c2c1d01261d6872ccbc76300befa41577dc4fe7e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page