Views
No views yet
1python3 -m venv .venv
2source .venv/bin/activate1pip install -U pip
2pip install -r requirements-dev.txtpython main.py --epochs 1 --batch_size 8main.py or by calling run_pipeline(config) in src/pipeline.py.data/raw by src/data_loader.DataLoader.download() using Hugging Face datasets.save_to_disk().pytest and are located in the tests/ folder. Run them with:pytest -qtests/test_data_loader.py: dataset download/load and DataLoader constructions (uses mocks)tests/test_facial_recognition.py: model shapes and frozen backbone checkstests/test_trainer.py: training loop behavioursmain.py: CLI entrypoint to run the pipelinesrc/: application code
data_loader.py: dataset download/persistence and PyTorch DataLoader wrappingpaths.py: project path constants (e.g., data/raw)pipeline.py: orchestrates data download, training, evaluation, artifact exporttrainer.py: training loop that consumes a DataProvider (returns a PyTorch DataLoader)evaluator.py: evaluation helpers and artifact export (metrics, confusion matrix)models/: model definitions (ResNet50 backbone + classifier head)data/: storage for raw and processed datasets
data/raw/: persisted Hugging Face dataset (created by save_to_disk())data/processed/: optional processed artifactsoutputs/: saved artifacts: metrics.json, confusion_matrix.png, etc.tests/: unit testsrequirements.txt and requirements-dev.txtDataLoader.download() calls datasets.load_dataset(REPO_ID) and then dataset.save_to_disk(data/raw).DataLoader.load() uses load_from_disk(data/raw).HuggingFaceImageDataset converts HF rows to PIL/Numpy images, applies Grayscale -> ToTensor -> Normalize transforms, and returns (image_tensor, label).resnet50 (most layers frozen except layer4 by default).Linear(in_features, embedding_size) followed by ReLU.Linear(embedding_size, num_classes) returning logits for CrossEntropyLoss.Trainer.fit() fetches train_loader and runs forward → loss (CrossEntropyLoss) → backward → optimizer.step().Evaluator runs model on the test loader, computes metrics and writes outputs/metrics.json and outputs/confusion_matrix.png.nn.CrossEntropyLoss. Reasons for this design:CrossEntropyLoss expects raw class logits and pairs naturally with evaluation metrics like accuracy, precision, and F1, making progress easy to interpret.CrossEntropyLoss implements log_softmax + nll_loss in a stable, optimized form and is the standard choice for multi-class classification.CrossEntropyLoss will produce meaningless loss values. Ensure model outputs are logits with shape (batch_size, num_classes).torch.long values in the range [0, num_classes-1].outputs.shape and targets.shape match expectations and dtypes are correct.torch.isnan() and output statistics).CrossEntropyLoss and a metric loss, implement simple contrastive sampling, or add runtime checks/logging to Trainer.fit() to surface the most common issues.1print(inputs.shape, inputs.dtype)
2print(targets.shape, targets.dtype, targets.min(), targets.max())1o = model(inputs)
2print(o.shape, o.mean().item(), o.std().item(), torch.isnan(o).any())1loss = criterion(o, targets)
2print(loss.item())