Views
No views yet
├── model.py # AlexNet architecture (5 conv + 3 fc)
├── load_data.py # ImageNet dataloaders & preprocessing
├── train.py # Training / validation loop & scheduler setup
├── models/ # (auto-created) checkpoints & logs
└── README.md # You are heremodel.py--init_weights.load_data.pyDataLoaders.train.py--warmup_epochs).--scheduler.models/top1_accuracy.txt and saves a checkpoint every 10 epochs.ILSVRC2012
├── train
│ ├── n01440764
│ │ ├── n01440764_10026.JPEG
│ │ └── ...
└── val
├── n01440764
│ ├── ILSVRC2012_val_00000293.JPEG
│ └── ...--root /path/to/ILSVRC2012.💡 ImageNet licence – obtaining the dataset requires registration with the ImageNet website.
1# (Optional) create a virtual environment
2python -m venv .venv && source .venv/bin/activate
3
4pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
5# or the CUDA wheels if you have a GPU1python train.py \
2 --root /datasets/ILSVRC2012 \
3 --device cuda:0 # or cpu / mps--epochs (default 100)--batch_size (default 128)--lr, --momentum, --weight_decay--scheduler step|cosine + --lr_step_size, --lr_gamma--warmup_epochs – linear warm-up length--save_dir – directory for checkpoints & logs1python train.py --root /datasets/ILSVRC2012 --device cuda \
2 --init_weights False \
3 --save_dir models \
4 --epochs 30
5# then inside train.py adapt: model.load_state_dict(torch.load('models/model_XX.pth'))1maxk = 5
2_, pred = logits.topk(maxk, 1, True, True) # (batch, 5)
3correct = pred.eq(labels.view(-1, 1).expand_as(pred))
4correct_top5 += correct.any(1).float().sum().item()Krizhevsky, Alex, Ilya Sutskever, and Geoffrey Hinton. "ImageNet classification with deep convolutional neural networks." NeurIPS 2012.