Files
hw3_cnns/README.md
T
2026-11-01 18:44:33 +01:00

136 lines
4.6 KiB
Markdown

# 🍎 DPL HW3 - Fruit Image Analysis
This repository contains the code for the third homework assignment of the **DPL course at CTU**. The task involves training a neural network to:
- 🏷️ **Classify** images of fruits into 30 different categories
- 🎨 **Segment** fruits with pixel-level masks
- 🔍 **Learn** meaningful image embeddings
---
## 📁 Repository Structure
```
hw3_students/
├── confs/ # Configuration files for the project
├── data/ # Directory to store datasets (create after downloading)
├── model.py # Neural network architecture definition
├── train.py # Model training script
├── train_job.sbatch # SLURM job script for cluster training
├── README.md # Project documentation
└── requirements.txt # Python dependencies
```
> 💡 **Note:** For cluster training details, see the [Course Page](https://urob-ctu.github.io/docs/)
---
## 🚀 Getting Started
### 1️⃣ Clone the repository
```bash
git clone git@github.com:urob-ctu/hw3-cnns.git
```
### 2️⃣ Set up your environment
Create a virtual environment and install dependencies:
```bash
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
### 3️⃣ Download the dataset
Download the dataset and place it in the `data/` directory: [Dataset Link](https://drive.google.com/file/d/1cnD0vsuPSM-lkV4zqCxvXYihuvc6s7PF/view?usp=sharing)
### 4️⃣ Configure your experiment
Modify the configuration file in `confs/config.yml` as needed.
### 5️⃣ Train the model
- Define your model in `model.py`
- Fill the missing lines in `train.py` (look for ‼️‼️‼️‼️) [or write your own training script but then submit this training script as `train.py`]
- Run the training script:
```bash
python train.py
```
### 6️⃣ (Optional) Use SLURM cluster
If using a SLURM cluster, submit the job using:
```bash
sbatch train_job.sbatch
```
---
## ✅ Your Tasks
1. 🏗️ **Implement** the neural network architecture in `model.py`
- must be named `MyModel` and accept `output_size` as an argument (output_size should be 30 for 30 fruit classes)
- `forward` method must return three outputs:
- class logits (shape: `[batch_size, 30]`)
- segmentation mask (shape: `[batch_size, 1, 64, 64]`)
- image embeddings (shape: `[batch_size, embedding_dim]`)
- `get_embedding` method must return single output:
- image embeddings (shape: `[batch_size, embedding_dim]`)
2. 🔄 **Complete** the training loop in `train.py` (look for ‼️‼️‼️‼️)
3. ⚙️ **Tune** hyperparameters in `confs/config.yml` for optimal performance
- use tensorboard to monitor training progress: `tensorboard --logdir {path_to_logs}`
4. 📋 **LLM statement**: create a file `llm_declaration.txt` where you briefly describe how and where you used LLMs while solving the task.
---
## 📊 Evaluation
### 🎯 Basic Evaluation (10 points)
This homework is worth **10 points**, distributed as follows:
| Task | Metric | Threshold | Points |
|------|--------|-----------|--------|
| **🍊 Fruit Classification** | Accuracy | 85% | 1 pt |
| | | 90% | 2 pts |
| **🎨 Segmentation Mask** | Mean IoU | 80% | 1 pt |
| | | 85% | 2 pts |
| | | 90% | 3 pts |
| **📈 Image Embeddings (ROC)** | AUC | 0.85 | 1 pt |
| | | 0.90 | 2 pts |
| **🎯 Image Embeddings (TPR)** | TPR @ 5% FPR | 0.80 | 1 pt |
| | | 0.85 | 2 pts |
| | | 0.90 | 3 pts |
## 📦 Submission
Submit your code as a **zip file** containing:
- ✅ `model.py` - Your neural network architecture
- ✅ `train.py` - Your training script
- ✅ `weights.pth` - Trained model weights (state_dict)
- ✅ `llm_declaration.txt` - Your LLM usage statement
> **Loading format:** Weights are loaded using:
> ```python
> model.load_state_dict(torch.load(weights_path, map_location=torch.device('cpu')))
> ```
---
## 🚫 Important Policies
### 🤖 Pretrained Models Policy
❌ You are **not allowed** to use any pretrained models or transfer learning techniques.
✅ All models **must be trained from scratch** using the provided dataset and your training code that you submit.
### 📝 Plagiarism Policy
✅ You are **strongly encouraged** to discuss ideas and approaches with your peers.
⚠️ However, the code you submit **must be your own work** and you must fully understand it.
❌ Copying code from others is **strictly prohibited** and will result in a **zero score** for the assignment.
---
<div align="center">
**Good luck! 🍀**
**In case of any questions, feel free to write me at hlavsja3@fel.cvut.cz and I will ask my LLM🔮**
</div>