项目依赖见ML/requirements.txt,执行以下命令安装:
cd ML
pip install -r requirements.txt- Python 3.8+
- CUDA 11.0+(建议,支持GPU加速)
- PyTorch 1.10+
DL方案使用ConvNeXt-Tiny预训练权重,下载链接: https://huggingface.co/timm/convnext_tiny.fb_in1k/resolve/main/model.safetensors?download=true
下载后存放路径:ML/models/weights/model.safetensors(需手动创建models/weights目录)。
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)
cd ML
bash run_DL_experiment.sh- 训练DL模型(支持10%/20%噪声比例):
python train_DL_experiment.py- 预测测试集结果:
# 10%噪声标签训练的模型预测
python predict_DL.py -r 10
# 20%噪声标签训练的模型预测
python predict_DL.py -r 20- 计算准确率:
python acc.py --model DLcd ML
bash run_ML_experiment.sh- 运行ML对比实验(包含不同特征、分类器、PCA、噪声清洗组合):
python train_ML_experiment.py- 计算准确率:
python acc.py --model MLML/
├── 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 # 依赖清单
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)
feature_type:特征提取方式(CNN/HOG/SIFT/LBP/COLOR)classifier:分类器(SVM/KNN)use_pca:是否使用PCA降维use_noise_clean:是否使用交叉验证清洗噪声标签noise_ratio:训练标签的噪声比例(10/20)
- DL实验结果:保存至
ML/Exp/DL/,包含训练的最佳模型、不同噪声比例的预测CSV、准确率文件DL_acc.txt。 - ML实验结果:保存至
ML/Exp/ML/,包含不同实验组合的预测CSV、准确率文件ML_acc.txt。 - 准确率文件:每行对应一个预测文件的名称和准确率(保留4位小数)。
- 请根据本地GPU设备调整配置文件中的
device参数(如cuda:0/cuda:1)。 - 若训练过程中出现数据加载错误,请检查数据集路径与CSV文件中的图像ID是否匹配。
- ML实验的特征提取(如SIFT/HOG)在CPU上运行较慢,建议使用GPU加速的CNN特征提取优先测试。
- 预训练权重和数据集下载后,请确保路径与配置文件中的
pretrained_weights、image_dir等参数一致。
Project dependencies are listed in ML/requirements.txt. Install them with the following command:
cd ML
pip install -r requirements.txt- Python 3.8+
- CUDA 11.0+ (Recommended for GPU acceleration)
- PyTorch 1.10+
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).
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)
cd ML
bash run_DL_experiment.sh- Train the DL model (supports 10%/20% noise ratios):
python train_DL_experiment.py- 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- Calculate accuracy:
python acc.py --model DLcd ML
bash run_ML_experiment.sh- Run ML comparison experiments (including combinations of different features, classifiers, PCA, and noise cleaning):
python train_ML_experiment.py- Calculate accuracy:
python acc.py --model MLML/
├── 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
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 epochslr_head/lr_backbone: Learning rate for classification head / backbone networkdevice: Training device (e.g., cuda:2)
feature_type: Feature extraction method (CNN/HOG/SIFT/LBP/COLOR)classifier: Classifier (SVM/KNN)use_pca: Whether to use PCA for dimensionality reductionuse_noise_clean: Whether to use cross-validation for noisy label cleaningnoise_ratio: Noise ratio of training labels (10/20)
- DL experiment results: Saved to
ML/Exp/DL/, including the best trained model, prediction CSVs for different noise ratios, and accuracy fileDL_acc.txt. - ML experiment results: Saved to
ML/Exp/ML/, including prediction CSVs for different experimental combinations and accuracy fileML_acc.txt. - Accuracy file: Each line corresponds to the name of a prediction file and its accuracy (retaining 4 decimal places).
- Adjust the
deviceparameter in the configuration file according to the local GPU device (e.g., cuda:0/cuda:1). - If a data loading error occurs during training, check whether the dataset path matches the image IDs in the CSV files.
- 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.
- After downloading the pre-trained weights and dataset, ensure that the paths are consistent with parameters such as
pretrained_weightsandimage_dirin the configuration file.