its able to run with clean for detector but not with classfier and reformer --model_type with minimal changes
Assistant
Looking at your code, I can see the issue. The problem is that when train_clean_only is True, you're using the direct clean dataloader (get_clean_only_dataloader) which creates a different data format than what the reformer and classifier training functions expect.
Let me explain the mismatch and provide a solution:Fixed train.py with proper clean-only training supportCode # train.py
"""
Comprehensive training script for FL-Purification
Supports individual model training, pipeline training, and data preparation
"""
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torcThe key issue was that you had two different dataloader creation approaches for clean-only training:
For detector: Using get_clean_only_dataloader() which directly creates clean data from the dataset
For classifier/reformer: Expecting data in the format (images, pert_labels, true_labels) from Kaggle datasets
The main changes I made:
New Function: create_clean_only_dataloaders_for_kaggle()
This function extracts only clean images from Kaggle attack datasets
Creates dataloaders in the format expected by all training functions: (images, pert_labels, true_labels)
Sets pert_labels to all zeros since everything is clean
New Function: create_mixed_dataloaders_for_kaggle()
Handles the original mixed (clean + adversarial) training
Uses the existing create_dataloader_from_kaggle_data() function
Unified Dataloader Creation
Both clean-only and mixed training now use the same data format
All models (detector, reformer, classifier) receive consistent data structure
Better Error Handling
Tries multiple attack types to find available Kaggle data
Provides clear error messages if data loading fails
Key Differences in Data Format:
Old detector approach (direct clean):
python# From get_clean_only_dataloader() - only works with detector
batch = (images, labels) # 2-tuple
New unified approach (from Kaggle datasets):
python# Consistent format for all models
batch = (images, pert_labels, true_labels) # 3-tuple
pert_labels = 0 for clean, 1 for adversarial
true_labels = actual classification labels
Now when you run with --train_clean_only, all models will receive data in the same format, which should resolve the issues you were having with reformer and classifier training.
The fixed code maintains backward compatibility while providing a unified approach that works with all model types in both clean-only and mixed training modes.