Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ __pycache__/

# Outputs
output/
outputs/
dataset/
assets/classification_dataset
assets/output_images/
data/classification_dataset
data/output_images/
database/data/

# Virtual environments
Expand All @@ -29,4 +27,8 @@ deepstream_engines/
.ssh/
.vscode-server/
.bash_history
.gitconfig
.gitconfig

# Dataset - exclude data files
dataset/data/
dataset/archives/*.zip
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@
}

# Create reverse lookup for dataset names
_DATASET_NAME_TO_ID: Dict[str, int] = {
name: class_id for class_id, name in DATASET_NAMES.items()
}
_DATASET_NAME_TO_ID: Dict[str, int] = {name: class_id for class_id, name in DATASET_NAMES.items()}


def map_prediction(model_class_id: int) -> int:
Expand Down

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a newline

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from pathlib import Path


def compress_dataset(dataset_path="assets/classification_dataset", output_path="classification_dataset.zip"):
def compress_dataset(
dataset_path="data/classification_dataset", output_path="dataset/archives/classification_dataset.zip"
):
"""
Compress the classification dataset into a ZIP archive.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path


def decompress_dataset(archive_path="classification_dataset.zip", output_dir="assets"):
def decompress_dataset(archive_path="dataset/archives/classification_dataset.zip", output_dir="data"):
"""
Decompress the classification dataset from a ZIP archive.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def create_largest_k_classification_dataset(
"""
images_dir = Path(data_root) / "images"
bboxes_dir = Path(data_root) / "bboxes" / "CropAndWeed"
output_dir = Path("assets") / "classification_dataset" / "images"
output_dir = Path("data") / "classification_dataset" / "images"
output_dir.mkdir(parents=True, exist_ok=True)

image_files = {img_file.stem: img_file for img_file in images_dir.glob("*.jpg")}
Expand All @@ -188,7 +188,7 @@ def create_largest_k_classification_dataset(
print("\n✂️ Creating dataset with LARGEST objects (Largest-K strategy)...")
stats, total_objects = save_largest_k_crops(eligible_classes, output_dir, max_objects_per_class)

stats_file = Path("assets") / "classification_dataset" / "dataset_stats_largest_k.json"
stats_file = Path("data") / "classification_dataset" / "dataset_stats_largest_k.json"
with open(stats_file, "w") as f:
json.dump(stats, f, indent=2)

Expand Down
32 changes: 16 additions & 16 deletions docs/dataset_preparation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ This project uses a **two-stage dataset preparation process**:

Download the original CropAndWeed dataset (5 tar archives, ~10,000 images) from the official source:
```bash
python dataset_preparation/dataset_prep.py --data_root ./dataset
python dataset/preparation/dataset_prep.py --data_root ./dataset/data
```
- **What gets downloaded:** Five large tar files containing images and annotations.
- **Expected download time:** Each archive is several GB; total time depends on your internet speed (typically 10–30 minutes).
- **Resulting structure:**
```
dataset/
├── images/
├── bboxes/
├── labelIds/
└── params/
dataset/data/
├── images/
├── bboxes/
├── labelIds/
└── params/
```

### Stage 2: Create Balanced Classification Dataset

Generate a balanced classification dataset (76 classes, 12 objects per class, 912 total) from the original data:
```bash
python dataset_preparation/prepare_crops_dataset.py --data_root ./dataset
python dataset/preparation/prepare_crops_dataset.py --data_root ./dataset/data
```
- **What happens:** The script filters and crops the original images using **PIL** to create a balanced classification dataset.
- **Output:**
```
classification_dataset/
data/classification_dataset/
├── images/
│ ├── 1/
│ ├── 2/
Expand All @@ -50,7 +50,7 @@ python dataset_preparation/prepare_crops_dataset.py --data_root ./dataset

If you only need the ready-to-use classification dataset, extract it directly:
```bash
python dataset_preparation/decompress_dataset.py
python dataset/preparation/decompress_dataset.py
```
- **What happens:** Extracts a pre-built balanced dataset (912 images, 76 classes) for immediate use.

Expand All @@ -75,7 +75,7 @@ The **CropAndWeed** dataset contains agricultural images with multi-level annota

### Native Format (Original)
```
dataset/
dataset/data/
├── images/ # RGB images (JPG format)
│ ├── ave-0000-0001.jpg
│ └── ...
Expand Down Expand Up @@ -163,10 +163,10 @@ To access the ready-to-use classification dataset:

```bash
# Extract classification dataset archive (updated with Largest-K)
python dataset_preparation/decompress_dataset.py
python dataset/preparation/decompress_dataset.py

# Or extract from custom location
python dataset_preparation/decompress_dataset.py classification_dataset.zip extracted_data/
python dataset/preparation/decompress_dataset.py dataset/archives/classification_dataset.zip extracted_data/
```

**Verification:** Script automatically verifies 912 images and 2 JSON files.
Expand All @@ -185,12 +185,12 @@ The following issues are known and documented as part of the Largest-K approach:

```bash
# Generate dataset with Largest-K strategy
python dataset_preparation/prepare_crops_dataset.py --data_root ./dataset
python dataset/preparation/prepare_crops_dataset.py --data_root ./dataset/data
```

### Output files:
- `assets/classification_dataset/images/` - Cropped objects organized by class
- `assets/classification_dataset/dataset_stats_largest_k.json` - Size distribution statistics
- `data/classification_dataset/images/` - Cropped objects organized by class
- `data/classification_dataset/dataset_stats_largest_k.json` - Size distribution statistics

---

Expand All @@ -205,4 +205,4 @@ python dataset_preparation/prepare_crops_dataset.py --data_root ./dataset
- **Full dataset** (~10k images, 85 classes)
- **Single-class images** (~1.5k images, ~60 classes)
- **Single-object images** (~500 images, ~40 classes)
- **Largest-K dataset** (912 images, 76 classes) - **Current approach**
- **Largest-K dataset** (912 images, 76 classes) - **Current approach**
2 changes: 1 addition & 1 deletion src/evaluation/run_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from src.evaluation.evaluator import EvaluationConfig, ModelEvaluator
from src.inference import MobileNetInference, ResNetInference
from src.onnx_model import OnnxClassifierInferenceBase as OnnxModel
from src.optimal_class_mapping import map_prediction
from dataset.optimal_class_mapping import map_prediction
from src.path_utils import ensure_clean_directory

MODELS_DIR_PATH = Path("models")
Expand Down
4 changes: 2 additions & 2 deletions src/evaluation/run_hierarchical_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

from PIL import Image

from dataset_preparation.utilities.datasets import DATASETS
from dataset.utilities.datasets import DATASETS
from metrics.metrics_api import compute_metrics
from src.evaluation.evaluator import EvaluationConfig, ModelEvaluator
from src.inference import MobileNetInference, ResNetInference
from src.optimal_class_mapping import map_prediction
from dataset.optimal_class_mapping import map_prediction


class MappedModelWrapper:
Expand Down
Loading