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.
- 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
- Python 3.8+
- CUDA 11.0+ (for GPU support)
- 4GB+ GPU memory recommended
- Clone the repository:
git clone https://github.com/yourusername/ocw-few-shot-learning.git
cd ocw-few-shot-learning- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- 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.
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%}")# 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 licsfrom 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')- Uses Euclidean distance for classification
- Equal weights for all classes
- Leverages cosine similarity for distance calculation
- Better handling of high-dimensional features
- Dynamic weight optimization based on class characteristics
- Iterative refinement using accuracy feedback
- Mathematical formulation:
w_i(t+1) = w_i(t) + ¥ç¡Ôaccuracy(w)
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.1If 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}
}We welcome contributions! Please see CONTRIBUTING.md for details.
This project is licensed under the MIT License - see the LICENSE file for details.
- This work was supported by IITP grant funded by the Korea government (MSIT)
- Thanks to Hugging Face for pre-trained models
- Built with PyTorch
For questions and feedback:
- Jieui Kang - 212aig08@ewhain.net