Skip to main content

Image classification trainer using OpenCV and timm

Project description

AEK Image Trainer Logo

AEK Image Trainer

AI image preprocessing library

Installation

pip install aek-img-trainer

For more secure way after doing that you can upgrade via:

pip install --upgrade aek-img-trainer

Usage

Create object

Now you can just use Trainer class methods example usage is shown below.

from aek_img_trainer import Trainer, Preprocessor

model = Trainer(train_root="root/trainset",
                val_root="root/valset",
                num_classes=16,
                img_size=224,
                batch_size=4,
                val_reach=0.9999,
                num_epochs=150,
                learning_rate=1e-3,
                checkpoint_path="efficientnet_b0_best_model.pth",
                model_name="efficientnet_b0",
                device=None,
                augment=True,
                scheduler=None,
                scheduler_params=None,
                pretrained=True)

Those hyperparameters without train and val dataset path are default if you want to use default parameters you can just give your train and val datasets' path.

model = Trainer(train_root="root/trainset",val_root="root/valset")

Training

You can train your model with parameter that created earlier.

model.train()

Prediction

You can use your model in test with below code.

model.predict(checkpoint_path="example_model.pth",
               test_path="root/test.png")

Or if you give the test set path this method predict all images in the dataset folder. Your dataset should be labelled like training dataset.

Example usage:

model.predict(checkpoint_path="example_model.pth",
                test_set_path="root/testset")

Save XML

You can save the pth model file to xml and bin files

Example usage:

model.savexml(
    pth_path="enfet.pth",
    output_path="enfet.xml",
    class_number=16,
    model_name="efficientnet_b0"
)

Prediction on XML file

You can predict the model with xml and bin files. Like above predict function predict_xml takes either test_path or test_set_path and changes the result with the given path, either predict one image or images that inside the test set. Test set should be labelled like a training dataset.

Example usage:

model.predict_xml(
    xml_path="efnet.xml",
    bin_path="efnet.bin",
    test_path=None,
    test_set_path="root/testset"
)

Information

You can see your model's parameters and architecture.

model.print_model_info()

Help function for Trainer class

You can use help() function for get more information about functions that inside the Trainer class.

model.help()

Timm models

You can get models that inside the timm library you can use with their name in string format inside the Trainer() 'model_name' paramaters. ATTENTION: You can just use the models whose head layers are 'fc', 'head' and 'classifier'

model.list_all_timm_models()

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

aek_img_trainer-0.5.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

aek_img_trainer-0.5.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file aek_img_trainer-0.5.1.tar.gz.

File metadata

  • Download URL: aek_img_trainer-0.5.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aek_img_trainer-0.5.1.tar.gz
Algorithm Hash digest
SHA256 92d52bd65d93fa57230d8d78f62c1e7bd612c211c495f6c41791db459823d499
MD5 7ccbbb0ec6499d1178da6b95b9c36d90
BLAKE2b-256 9660de1b4591c731b974099029dfc4a8cf73fa55581ed5e1e8d567257a8431a2

See more details on using hashes here.

File details

Details for the file aek_img_trainer-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aek_img_trainer-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ea6831145be6bcda8142f32d99964f79e31ad67580e0ba7901fb6df84783fd86
MD5 fcb288408ec25e04338229719267f045
BLAKE2b-256 30a85b104e08a4155af506c34e1c0c5d0233db8bdcfc34e8a082ff304b5a5396

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