Skip to content

About

Caltech101 image classification with noisy labels (DL/ML comparison)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Caltech101 噪声标签图像分类实验

Jump to English Version

1. 项目环境准备

1.1 依赖安装

项目依赖见ML/requirements.txt,执行以下命令安装:

cd ML
pip install -r requirements.txt

1.2 环境要求

  • Python 3.8+
  • CUDA 11.0+(建议,支持GPU加速)
  • PyTorch 1.10+

2. 数据与预训练权重

2.1 预训练权重

DL方案使用ConvNeXt-Tiny预训练权重,下载链接: https://huggingface.co/timm/convnext_tiny.fb_in1k/resolve/main/model.safetensors?download=true

下载后存放路径:ML/models/weights/model.safetensors(需手动创建models/weights目录)。

2.2 数据集

Caltech101带噪声标签数据集下载链接: https://drive.google.com/file/d/15BXnGEPnHraL-TP2K7OiiH8RjVJBJoRi/view?usp=drive_link

数据集解压后需按如下结构存放:

ML/
└── caltech101_noise/
    ├── train/
    │   ├── images/       # 训练集图像(*.png)
    │   ├── labels_noisy_10.csv  # 10%噪声标签
    │   └── labels_noisy_20.csv  # 20%噪声标签
    └── test/
        └── images/        # 测试集图像(*.png)

3. 实验运行

3.1 深度学习(DL)实验

3.1.1 一键运行(训练+预测+准确率计算)

cd ML
bash run_DL_experiment.sh

3.1.2 分步运行

  1. 训练DL模型(支持10%/20%噪声比例):
python train_DL_experiment.py
  1. 预测测试集结果:
# 10%噪声标签训练的模型预测
python predict_DL.py -r 10
# 20%噪声标签训练的模型预测
python predict_DL.py -r 20
  1. 计算准确率:
python acc.py --model DL

3.2 机器学习(ML)实验

3.2.1 一键运行(训练+预测+准确率计算)

cd ML
bash run_ML_experiment.sh

3.2.2 分步运行

  1. 运行ML对比实验(包含不同特征、分类器、PCA、噪声清洗组合):
python train_ML_experiment.py
  1. 计算准确率:
python acc.py --model ML

4. 代码结构说明

ML/
├── config/                # 配置文件目录
│   ├── DL_config.yaml     # DL实验配置(模型、训练、数据等)
│   └── ML_config.yaml     # ML实验配置(特征、分类器、PCA等)
├── models/
│   ├── DL.py              # DL模型训练逻辑(ConvNeXt)
│   └── ML.py              # ML模型训练/预测逻辑(SVM/KNN+特征提取)
├── utils/
│   └── utils.py           # 工具函数(图像加载、特征提取、数据增强、Loss等)
├── train_DL.py            # DL单轮训练入口
├── train_DL_experiment.py # DL多噪声比例实验入口
├── predict_DL.py          # DL模型预测入口
├── train_ML.py            # ML单轮训练入口
├── train_ML_experiment.py # ML多组合实验入口
├── acc.py                 # 准确率计算脚本
├── run_DL_experiment.sh   # DL实验一键运行脚本
├── run_ML_experiment.sh   # ML实验一键运行脚本
└── requirements.txt       # 依赖清单

5. 关键配置说明

5.1 DL配置(DL_config.yaml)

  • noise_ratio:训练标签的噪声比例(10/20)
  • model_name:DL模型名称(默认convnext_tiny.fb_in1k)
  • num_classes:分类类别数(Caltech101为102)
  • batch_size/epochs:训练批次大小、轮数
  • lr_head/lr_backbone:分类头/骨干网络学习率
  • device:训练设备(如cuda:2)

5.2 ML配置(ML_config.yaml)

  • feature_type:特征提取方式(CNN/HOG/SIFT/LBP/COLOR)
  • classifier:分类器(SVM/KNN)
  • use_pca:是否使用PCA降维
  • use_noise_clean:是否使用交叉验证清洗噪声标签
  • noise_ratio:训练标签的噪声比例(10/20)

6. 输出说明

  • DL实验结果:保存至ML/Exp/DL/,包含训练的最佳模型、不同噪声比例的预测CSV、准确率文件DL_acc.txt。
  • ML实验结果:保存至ML/Exp/ML/,包含不同实验组合的预测CSV、准确率文件ML_acc.txt。
  • 准确率文件:每行对应一个预测文件的名称和准确率(保留4位小数)。

注意事项

  1. 请根据本地GPU设备调整配置文件中的device参数(如cuda:0/cuda:1)。
  2. 若训练过程中出现数据加载错误,请检查数据集路径与CSV文件中的图像ID是否匹配。
  3. ML实验的特征提取(如SIFT/HOG)在CPU上运行较慢,建议使用GPU加速的CNN特征提取优先测试。
  4. 预训练权重和数据集下载后,请确保路径与配置文件中的pretrained_weights、image_dir等参数一致。

Caltech101 Image Classification Experiment with Noisy Labels

跳转到中文版本

1. Project Environment Preparation

1.1 Dependency Installation

Project dependencies are listed in ML/requirements.txt. Install them with the following command:

cd ML
pip install -r requirements.txt

1.2 Environment Requirements

  • Python 3.8+
  • CUDA 11.0+ (Recommended for GPU acceleration)
  • PyTorch 1.10+

2. Data and Pre-trained Weights

2.1 Pre-trained Weights

The DL scheme adopts ConvNeXt-Tiny pre-trained weights. Download link: https://huggingface.co/timm/convnext_tiny.fb_in1k/resolve/main/model.safetensors?download=true

Save path after downloading: ML/models/weights/model.safetensors (You need to manually create the models/weights directory).

2.2 Dataset

Download link for Caltech101 dataset with noisy labels: https://drive.google.com/file/d/15BXnGEPnHraL-TP2K7OiiH8RjVJBJoRi/view?usp=drive_link

After unzipping the dataset, organize it in the following structure:

ML/
└── caltech101_noise/
    ├── train/
    │   ├── images/       # Training set images (*.png)
    │   ├── labels_noisy_10.csv  # 10% noisy labels
    │   └── labels_noisy_20.csv  # 20% noisy labels
    └── test/
        └── images/        # Test set images (*.png)

3. Experiment Execution

3.1 Deep Learning (DL) Experiment

3.1.1 One-click Run (Training + Prediction + Accuracy Calculation)

cd ML
bash run_DL_experiment.sh

3.1.2 Step-by-step Run

  1. Train the DL model (supports 10%/20% noise ratios):
python train_DL_experiment.py
  1. Predict test set results:
# Prediction with model trained on 10% noisy labels
python predict_DL.py -r 10
# Prediction with model trained on 20% noisy labels
python predict_DL.py -r 20
  1. Calculate accuracy:
python acc.py --model DL

3.2 Machine Learning (ML) Experiment

3.2.1 One-click Run (Training + Prediction + Accuracy Calculation)

cd ML
bash run_ML_experiment.sh

3.2.2 Step-by-step Run

  1. Run ML comparison experiments (including combinations of different features, classifiers, PCA, and noise cleaning):
python train_ML_experiment.py
  1. Calculate accuracy:
python acc.py --model ML

4. Code Structure Explanation

ML/
├── config/                # Configuration file directory
│   ├── DL_config.yaml     # DL experiment configuration (model, training, data, etc.)
│   └── ML_config.yaml     # ML experiment configuration (features, classifier, PCA, etc.)
├── models/
│   ├── DL.py              # DL model training logic (ConvNeXt)
│   └── ML.py              # ML model training/prediction logic (SVM/KNN + feature extraction)
├── utils/
│   └── utils.py           # Utility functions (image loading, feature extraction, data augmentation, Loss, etc.)
├── train_DL.py            # DL single-round training entry
├── train_DL_experiment.py # DL multi-noise ratio experiment entry
├── predict_DL.py          # DL model prediction entry
├── train_ML.py            # ML single-round training entry
├── train_ML_experiment.py # ML multi-combination experiment entry
├── acc.py                 # Accuracy calculation script
├── run_DL_experiment.sh   # DL experiment one-click run script
├── run_ML_experiment.sh   # ML experiment one-click run script
└── requirements.txt       # Dependency list

5. Key Configuration Explanation

5.1 DL Configuration (DL_config.yaml)

  • noise_ratio: Noise ratio of training labels (10/20)
  • model_name: DL model name (default: convnext_tiny.fb_in1k)
  • num_classes: Number of classification classes (102 for Caltech101)
  • batch_size/epochs: Training batch size and epochs
  • lr_head/lr_backbone: Learning rate for classification head / backbone network
  • device: Training device (e.g., cuda:2)

5.2 ML Configuration (ML_config.yaml)

  • feature_type: Feature extraction method (CNN/HOG/SIFT/LBP/COLOR)
  • classifier: Classifier (SVM/KNN)
  • use_pca: Whether to use PCA for dimensionality reduction
  • use_noise_clean: Whether to use cross-validation for noisy label cleaning
  • noise_ratio: Noise ratio of training labels (10/20)

6. Output Explanation

  • DL experiment results: Saved to ML/Exp/DL/, including the best trained model, prediction CSVs for different noise ratios, and accuracy file DL_acc.txt.
  • ML experiment results: Saved to ML/Exp/ML/, including prediction CSVs for different experimental combinations and accuracy file ML_acc.txt.
  • Accuracy file: Each line corresponds to the name of a prediction file and its accuracy (retaining 4 decimal places).

Notes

  1. Adjust the device parameter in the configuration file according to the local GPU device (e.g., cuda:0/cuda:1).
  2. If a data loading error occurs during training, check whether the dataset path matches the image IDs in the CSV files.
  3. Feature extraction (e.g., SIFT/HOG) in ML experiments runs slowly on CPU. It is recommended to first test with GPU-accelerated CNN feature extraction.
  4. After downloading the pre-trained weights and dataset, ensure that the paths are consistent with parameters such as pretrained_weights and image_dir in the configuration file.

About

Caltech101 image classification with noisy labels (DL/ML comparison)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages