Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OCW: Optimized Class-Weighting for Few-Shot Learning

Overview

This repository contains the official implementation of "OCW: Enhancing Few-Shot Learning with Optimized Class-Weighting Methods". The OCW method is designed to improve model accuracy in few-shot learning scenarios by optimizing the allocation of weights to different classes in a dataset.

Key Features

  • State-of-the-art Performance: Consistent improvement across MobileNetV2, ViT, ResNet50, and EfficientNet
  • Flexible Framework: Support for 1-shot to 5-shot learning scenarios
  • Robust Method: Works well with both High Intra-Class Similarity (HICS) and Low Intra-Class Similarity (LICS) datasets
  • Comprehensive Evaluation: Includes visualization tools for confusion matrices and PCA analysis

Installation

Prerequisites

  • Python 3.8+
  • CUDA 11.0+ (for GPU support)
  • 4GB+ GPU memory recommended

Setup

  1. Clone the repository:
git clone https://github.com/yourusername/ocw-few-shot-learning.git
cd ocw-few-shot-learning
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt

Supported Datasets

  • HICS Dataset (High Intra-Class Similarity): Similar classes like fruits
    • Classes: apple, cherry, grape, mango, peach, etc.
  • LICS Dataset (Low Intra-Class Similarity): Diverse object classes
    • Classes: box, card, doorpull, extinguisher, hanger, etc.

Quick Start

Training with OCW Method

from src.train import FewShotTrainer
from config import load_config

# Load configuration
config = load_config('config/config.yaml')

# Initialize trainer
trainer = FewShotTrainer(
    model_name='mobilenetv2',
    method='ocw',
    n_shot=5,
    dataset_type='lics'
)

# Train and evaluate
results = trainer.train_and_evaluate()
print(f"Accuracy: {results['accuracy']:.2%}")

Running Experiments

# Run experiments for all models and methods
python experiments/run_experiments.py --dataset lics --shots 1 2 3 4 5

# Run specific experiment
python src/train.py --model mobilenetv2 --method ocw --shot 5 --dataset lics

Visualization

from src.utils.visualization import Visualizer

# Create confusion matrix
viz = Visualizer()
viz.plot_confusion_matrix(y_true, y_pred, class_names)

# PCA visualization
viz.plot_pca_features(features, labels, save_path='results/figures/pca.png')

Methods

1. Original Method (Baseline)

  • Uses Euclidean distance for classification
  • Equal weights for all classes

2. Cosine Similarity Method

  • Leverages cosine similarity for distance calculation
  • Better handling of high-dimensional features

3. OCW Method (Ours)

  • Dynamic weight optimization based on class characteristics
  • Iterative refinement using accuracy feedback
  • Mathematical formulation:
w_i(t+1) = w_i(t) + ¥ç¡Ôaccuracy(w)

Configuration

Edit config/config.yaml to customize:

model:
  name: mobilenetv2  # Options: mobilenetv2, vit, resnet50, efficientnet
  pretrained: true

training:
  n_shot: 5
  batch_size: 32
  learning_rate: 0.001
  
method:
  type: ocw  # Options: original, cosine, ocw
  optimization:
    iterations: 100
    step_size: 0.1

Citation

If you find this work useful, please cite our paper:

@inproceedings{kang2024ocw,
  title={OCW: Enhancing Few-Shot Learning with Optimized Class-Weighting Methods},
  author={Kang, Jieui and Lee, Subean and Kim, Eunseo and Choi, Soeun and Sim, Jaehyeong},
  booktitle={2024 International Conference on Communications, Computing, Cybersecurity, and Informatics (CCCI)},
  pages={1--8},
  year={2024},
  organization={IEEE}
}

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details.

License

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

Acknowledgments

  • This work was supported by IITP grant funded by the Korea government (MSIT)
  • Thanks to Hugging Face for pre-trained models
  • Built with PyTorch

Contact

For questions and feedback:


About

Optimized Class-Weighting for Few-Shot Learning

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages