Skip to main content

A package for fine-tuning deep learning models with Siamese architecture and triplet loss

Project description

DeepTuner

Description

DeepTuner is an open source Python package for fine-tuning computer vision (CV) based deep models. It supports multiple architectures including Siamese Networks with triplet loss and ArcFace with additive angular margin loss. The package provides various model backbones, data preprocessing tools, and evaluation metrics.

Installation

To install the package, use the following command:

pip install DeepTuner

Usage

Training with ArcFace

DeepTuner now supports ArcFace training with additive angular margin loss, which is particularly effective for face recognition tasks:

from deeptuner.backbones.resnet import ResNetBackbone
from deeptuner.losses.arcface_loss import ArcFaceModel, arcface_loss
from deeptuner.datagenerators.arcface_generator import ArcFaceDataGenerator

# Create data generators
train_generator = ArcFaceDataGenerator(
    data_dir='path/to/train/data',
    batch_size=32,
    image_size=(224, 224),
    augment=True
)

# Create backbone and ArcFace model
backbone = ResNetBackbone(input_shape=(224, 224, 3))
backbone_model = backbone.create_model()

model = ArcFaceModel(
    backbone=backbone_model,
    num_classes=num_classes,
    embedding_dim=512,
    margin=0.5,
    scale=64.0
)

# Compile and train
model.compile(
    optimizer='adam',
    loss=arcface_loss(),
    metrics=['accuracy']
)

model.fit(
    train_generator.create_dataset(is_training=True),
    epochs=50
)

Fine-tuning Models with Siamese Architecture and Triplet Loss

For similarity learning tasks, you can use the Siamese architecture with triplet loss:

from deeptuner.backbones.resnet import ResNetBackbone
from deeptuner.architectures.siamese import SiameseArchitecture
from deeptuner.losses.triplet_loss import triplet_loss
from deeptuner.datagenerators.triplet_data_generator import TripletDataGenerator

# Create data generators
train_generator = TripletDataGenerator(
    train_paths, train_labels, 
    batch_size=32,
    image_size=(224, 224),
    num_classes=num_classes
)

# Create Siamese network
backbone = ResNetBackbone(input_shape=(224, 224, 3))
embedding_model = backbone.create_model()
siamese_architecture = SiameseArchitecture(
    input_shape=(224, 224, 3),
    embedding_model=embedding_model
)
siamese_network = siamese_architecture.create_siamese_network()

# Train the model
model.compile(optimizer='adam', loss=triplet_loss(margin=0.5))
model.fit(train_generator, epochs=50)

Features

  • Multiple architectures:
    • Siamese Networks with triplet loss
    • ArcFace with additive angular margin loss
  • Various backbone models:
    • ResNet
    • EfficientNet
    • MobileNet
  • Specialized data generators:
    • TripletDataGenerator for Siamese networks
    • ArcFaceDataGenerator for ArcFace training
  • Training utilities:
    • Fine-tuning callbacks
    • Learning rate scheduling
    • Wandb integration for experiment tracking

Configuration

You can use a configuration file (e.g., JSON) to store hyperparameters. Example config for ArcFace:

{
    "data_dir": "path/to/data",
    "image_size": [224, 224],
    "batch_size": 32,
    "epochs": 50,
    "learning_rate": 0.001,
    "patience": 5,
    "unfreeze_layers": 10,
    "embedding_dim": 512,
    "arcface_margin": 0.5,
    "arcface_scale": 64.0
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

deeptuner-0.2.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

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

deeptuner-0.2.0-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file deeptuner-0.2.0.tar.gz.

File metadata

  • Download URL: deeptuner-0.2.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for deeptuner-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8e7f7f28980597e99bc1d5fda7b41f47fe5f41fc6123685abe7c1af1959377be
MD5 3d5e037360c707259899e6428581e5b4
BLAKE2b-256 39eb8e13d4b5395384345c57ba7644ce07a6ecfe3fd6c62e3ed2c33eab597dfa

See more details on using hashes here.

File details

Details for the file deeptuner-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: deeptuner-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for deeptuner-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1978ad5c586d4560b56dfef2e7bb7d9a6fd97cda144484e049f308b49fbea703
MD5 fc05de8adee3821816740a905c9db22f
BLAKE2b-256 c939440d20609d5063f90d36ddadf2a98fb1768f84c02124b14b7b956659e43a

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