Skip to content
Draft
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ src/.DS_Store
# in progress / trials
scripts/

# Generated demo outputs
docs/demos/outputs/

/.vscode/settings.json

*.hdf5
.coverage
.coverage*
site/
20 changes: 20 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Build/Test Commands
- Install: `pip install -e .`
- Run tests: `pytest`
- Run single test: `pytest tests/test_file.py::TestClass::test_function -v`
- Run with coverage: `pytest --cov=src/cityseg --cov-report=term`

## Code Style Guidelines
- Follow PEP 8 for Python code style
- Use type hints for all function parameters and return values
- Import organization: standard library, third-party, local modules (alphabetically within groups)
- Use docstrings for all modules, classes, and functions (including parameters and return values)
- Error handling: Use custom exceptions from exceptions.py
- Naming: snake_case for variables/functions, PascalCase for classes
- Path handling: Use pathlib.Path instead of strings
- Logging: Use loguru.logger with appropriate levels
- Testing: Use pytest fixtures and parametrize for test cases
73 changes: 57 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

CitySeg is a flexible and efficient semantic segmentation pipeline for processing images and videos of urban environments. It supports multiple segmentation models and datasets, with capabilities for processing high-resolution inputs and comprehensive result analysis.

> **Version 0.4.0** introduces a complete reorganization to a modular component-based architecture, with enhanced testing infrastructure and improved storage mechanisms. The legacy interface remains available for backward compatibility. See the [Changelog](docs/changelog.md) for details.

## Features

- Support for multiple segmentation models (OneFormer)
Expand All @@ -10,8 +12,10 @@ CitySeg is a flexible and efficient semantic segmentation pipeline for processin
- Comprehensive analysis of segmentation results, including category-wise statistics
- Support for both image and video inputs
- Multi-video processing capability for entire directories
- Caching of processed segmentation maps in HDF5 format for quick re-analysis
- Output includes segmentation maps, colored segmentations, overlay visualizations, and detailed CSV reports
- Efficient storage using Zarr for segmentation data and Parquet for analysis results
- Intelligent caching and workflow management with Hamilton
- Output includes segmentation maps, colored segmentations, overlay visualizations
- Proper resource management for videos and memory-efficient processing
- Configurable logging with console and file outputs

## Installation
Expand Down Expand Up @@ -40,8 +44,11 @@ CitySeg requires the following main packages:
- opencv-python (cv2)
- numpy
- Pillow (PIL)
- h5py
- pandas
- xarray
- zarr
- pyarrow
- hamilton
- tqdm
- pyyaml
- loguru
Expand All @@ -61,9 +68,32 @@ For a complete list of dependencies, please refer to the `pyproject.toml` file.
Optional arguments:
- `--log-level`: Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
- `--verbose`: Enable verbose logging
- `--cache-dir`: Directory to use for caching intermediate results
- `--disable-cache`: Disable caching of intermediate results

3. The pipeline will process the input and generate various outputs including segmentation maps, visualizations, and analysis reports.

## Storage and Caching

CitySeg uses modern data formats for efficient storage and retrieval:

- **Zarr** for n-dimensional segmentation data
- Chunked storage for efficient access to video frames
- Compressed storage to reduce disk usage
- Metadata embedded directly with the data

- **Parquet** for tabular analysis results
- Highly efficient columnar storage
- Advanced filtering and querying capabilities
- Great performance for analytical workloads

- **Hamilton** for workflow management
- Automatic caching of intermediate results
- Precise dependency tracking between steps
- Function-level granularity for optimal reuse

These improvements significantly reduce memory usage and improve performance, especially for large video files and when reprocessing with the same configuration.

## Configuration

Here's an example of a basic configuration file:
Expand Down Expand Up @@ -113,21 +143,32 @@ Confirmed not to work due to issues with the Hugging Face pipeline:

## Project Structure

The project is organized into several Python modules, each serving a specific purpose within the CitySeg pipeline:
The project has been reorganized into a modular component-based architecture for better maintainability and extensibility:

- `main.py`: Entry point of the application, responsible for initializing and running the segmentation pipeline.
- `config.py`: Defines configuration classes and handles loading and validating configuration settings.
- `pipeline.py`: Implements the core segmentation pipeline, including model loading and inference.
- `processors.py`: Contains classes for processing images, videos, and directories, managing the segmentation workflow.
- `segmentation_analyzer.py`: Provides functionality for analyzing segmentation results, including computing statistics and generating reports.
- `video_file_iterator.py`: Implements an iterator for efficiently processing multiple video files in a directory.
- `visualization_handler.py`: Handles the visualization of segmentation results using color palettes.
- `file_handler.py`: Manages file operations related to saving and loading segmentation data and metadata.
- `utils.py`: Provides utility functions for various tasks, including data handling and logging.
- `palettes.py`: Defines color palettes for different datasets used in segmentation.
- `exceptions.py`: Custom exception classes for error handling throughout the pipeline.

This modular structure allows for easy maintenance and extension of the CitySeg pipeline, facilitating the addition of new features and models.
- `core/`: Core functionality and configuration:
- `config.py`: Configuration classes and validation
- `exceptions.py`: Custom exception classes for error handling
- `components/`: Modular components implementing core functionality:
- `image.py`: Image processing operations
- `video.py`: Video handling and frame extraction
- `segmentation.py`: Segmentation model integration
- `dataset.py`: Dataset handling and management
- `pipeline.py`: Pipeline creation and coordination
- `analysis/`: Analysis and visualization:
- `analyzer.py`: Segmentation analysis and metrics
- `visualization.py`: Visualization of segmentation results
- `storage/`: Data storage and retrieval:
- `storage.py`: Zarr and Parquet storage adapters
- `utils/`: Utility functions:
- `common.py`: Common utility functions
- `palettes.py`: Color palettes for different datasets
- `workflow/`: Hamilton-based workflow engine:
- `hamilton.py`: Workflow definitions and execution
- `legacy/`: Backwards compatibility adapters:
- `processors.py`: Legacy processor interface

This modular structure allows for easy maintenance and extension of the CitySeg pipeline, with clear separation of concerns between components.

## Logging

Expand Down
6 changes: 6 additions & 0 deletions docs/api/analysis/analyzer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Segmentation Analyzer

::: cityseg.analysis.analyzer
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/analysis/visualization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Visualization Handler

::: cityseg.analysis.visualization
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/components/dataset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Dataset Component

::: cityseg.components.dataset
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/components/image.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Image Component

::: cityseg.components.image
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/components/pipeline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Pipeline Component

::: cityseg.components.pipeline
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/components/segmentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Segmentation Component

::: cityseg.components.segmentation
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/components/video.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Video Component

::: cityseg.components.video
options:
members: true
parameter_headings: true
6 changes: 0 additions & 6 deletions docs/api/config.md

This file was deleted.

6 changes: 6 additions & 0 deletions docs/api/core/config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Config Module

::: cityseg.core.config
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/core/exceptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Exceptions Module

::: cityseg.core.exceptions
options:
members: true
parameter_headings: true
6 changes: 0 additions & 6 deletions docs/api/exceptions.md

This file was deleted.

10 changes: 0 additions & 10 deletions docs/api/handlers.md

This file was deleted.

6 changes: 6 additions & 0 deletions docs/api/legacy/processors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Legacy Processors

::: cityseg.legacy.processors
options:
members: true
parameter_headings: true
6 changes: 0 additions & 6 deletions docs/api/palettes.md

This file was deleted.

6 changes: 0 additions & 6 deletions docs/api/pipeline.md

This file was deleted.

13 changes: 0 additions & 13 deletions docs/api/processors.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/api/segments_analysis.md

This file was deleted.

6 changes: 6 additions & 0 deletions docs/api/storage/storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Storage Module

::: cityseg.storage.storage
options:
members: true
parameter_headings: true
6 changes: 0 additions & 6 deletions docs/api/utils.md

This file was deleted.

6 changes: 6 additions & 0 deletions docs/api/utils/common.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Common Utilities

::: cityseg.utils.common
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/utils/palettes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Palettes Module

::: cityseg.utils.palettes
options:
members: true
parameter_headings: true
6 changes: 6 additions & 0 deletions docs/api/workflow/hamilton.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Hamilton Workflow

::: cityseg.workflow.hamilton
options:
members: true
parameter_headings: true
24 changes: 23 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,29 @@ All notable changes to CitySeg will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.4.0] - Development

### Added
- Comprehensive test fixtures system for reproducible testing
- Integration tests focused on direct component interactions
- Test helpers for common assertions and data generation
- New modular component-based architecture

### Changed
- Complete codebase reorganization into modular structure
- Refactored into component-based architecture with clear separation of concerns
- Moved configuration and exceptions to core/ directory
- Split processing functionality into specialized components
- Improved legacy adapter layer for backward compatibility
- Simplified test structure with focused integration tests
- Enhanced storage layer with Zarr and Parquet adapters
- Improved video resource management

### Removed
- Deprecated monolithic processor classes (moved to legacy namespace)
- Redundant test files (archived for reference)

## [0.3.1] - 2024-04-15

### Added
- Initial release of CitySeg
Expand Down
35 changes: 35 additions & 0 deletions docs/demos/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CitySeg Demos

This directory contains demo scripts and notebooks that showcase how to use CitySeg.

## Available Demos

- `component_demo.ipynb` - Demonstrates the component-based architecture introduced in CitySeg 0.4.0

## Example Inputs

The `example_inputs/` directory contains sample images and videos for use with the demos:

- `EustonTap-Screenshot1.png` - Sample street scene image
- `CaledonianPark1_15s_3840x2160.mov` - Sample street scene video (15 seconds)

## Running the Demos

The Python scripts can be run directly:

```bash
cd docs/demos
python component_demo.ipynb
```

Or converted to Jupyter notebooks using [jupytext](https://github.com/mwouts/jupytext):

```bash
pip install jupytext
jupytext --to notebook component_demo.ipynb
jupyter notebook component_demo.ipynb
```

## Note on Output Directory

The demos will create an `outputs/` directory to store generated visualizations and results.
Loading
Loading