Model Finetuning

Model Finetuning

Finetune pre-trained models on your own data to achieve high accuracy on your specific task. Start from a foundation model and adapt it to your domain.

What is Finetuning?

Finetuning takes a model that was pre-trained on a large dataset and continues training it on your smaller, task-specific dataset. This gives you:

  • Better accuracy than training from scratch
  • Less data required (hundreds instead of millions of examples)
  • Faster training (minutes to hours instead of days)
  • Domain expertise the base model didn’t have
graph LR
    A[Pre-trained Model
General Knowledge] --> B[Your Dataset
Domain-Specific] B --> C[Finetuned Model
Your Task Expert] style A fill:#e0f2fe style B fill:#fef3c7 style C fill:#d1fae5

When to Finetune

ScenarioRecommendation
Standard task, enough labeled dataFinetune a pre-trained model
Very specific domain (medical, legal)Finetune with domain data
Limited labeled data (<100 examples)Use few-shot or consider LLM
Need maximum accuracyFinetune + hyperparameter tuning
Need fast inferenceFinetune small model or distill

Guide Sections

Quick Start

1. Prepare Your Dataset

from seeme import Client

client = Client()

## Create a dataset
dataset = client.create_dataset(
    name="Product Defect Classifier",
    task_type="image_classification"
)

version = client.create_dataset_version(
    dataset_id=dataset.id,
    name="v1"
)

# Create splits
train_split = client.create_split(version_id=version.id, name="train")
val_split = client.create_split(version_id=version.id, name="validation")

# Create labels
labels = ["good", "scratch", "dent", "discoloration"]
for label_name in labels:
    client.create_label(version_id=version.id, name=label_name)

# Upload and label data
for image_path, label in training_data:
    item = client.create_dataset_item(
        version_id=version.id,
        split_id=train_split.id,
        file_path=image_path
    )
    client.annotate(
        dataset_id=dataset.id,
        dataset_version_id=version.id,
        annotation=Annotation(
            item_id=item.id,
            split_id=train_split.id,
            label_id=label
        )
    )

2. Start Training

# Create finetuning job
job = client.create_job(
    dataset_id=dataset.id,
    version_id=version.id,
    name="Defect Classifier v1",
    job_type="finetune",
    config={
        "base_model": "efficientnet_b0",  # Pre-trained model
        "epochs": 20,
        "learning_rate": 0.001,
        "batch_size": 32,
        "image_size": 224,
        "freeze_layers": "early",  # Freeze early layers
        "augmentation": {
            "horizontal_flip": True,
            "rotation": 15,
            "brightness": 0.2
        }
    }
)

print(f"Training job started: {job.id}")

3. Monitor Progress

import time

while job.status in ["pending", "running"]:
    time.sleep(30)
    job = client.get_job(job.id)

    if job.metrics:
        print(f"Epoch {job.metrics.get('epoch', '?')}: "
              f"loss={job.metrics.get('loss', '?'):.4f}, "
              f"accuracy={job.metrics.get('accuracy', '?'):.2%}")

print(f"Training complete: {job.status}")
if job.status == "completed":
    model = client.get_model(job.model_id)
    print(f"Model accuracy: {model.metrics['accuracy']:.2%}")

Supported Task Types

TaskBase ModelsData Required
Image ClassificationEfficientNet, ResNet, MobileNet, ViT100-1000+ images per class
Object DetectionYOLOv4, YOLOv5, Faster R-CNN100-500+ annotated images
Text ClassificationBERT, DistilBERT, RoBERTa100-1000+ examples per class
Named Entity RecognitionspaCy, BERT-NER500-2000+ annotated sentences
TabularXGBoost, LightGBM, CatBoost1000+ rows

Finetuning vs. Other Approaches

ApproachWhen to UseData NeededTraining Time
FinetuningTask-specific accuracy needed100-10,000Minutes-Hours
Training from scratchUnique architecture needed10,000+Hours-Days
Transfer learningSimilar task to base model50-500Minutes
Few-shot (LLM)Very limited data5-50None
DistillationNeed smaller/faster modelLabeled by teacherHours

Best Practices

  1. Start with a good base model - Choose one trained on similar data
  2. Use the right learning rate - Lower than training from scratch (0.0001-0.001)
  3. Freeze early layers - Keep general features, train task-specific ones
  4. Augment your data - Especially if dataset is small
  5. Monitor for overfitting - Watch validation loss diverge from training loss
  6. Save checkpoints - Keep models from different epochs
  7. Test on held-out data - Never evaluate on training data

Next Steps

Start with Prepare Data to get your dataset ready for finetuning.