# keras-team/keras-cv architecture

> Architecture diagram of the GitHub repository keras-team/keras-cv, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/keras-team/keras-cv
- Repository: https://github.com/keras-team/keras-cv

## Overview

##### Project type and purpose
- This is an open-source Python library (KerasCV) providing a modular computer-vision SDK on top of Keras 2/3, with multi-backend support for TensorFlow, JAX, and PyTorch.
- Its purpose is to expose standardized APIs (layers, models, metrics, callbacks, datasets, custom ops) for building, training, and deploying vision pipelines.

##### File structure
- Top-level directories & files:
- keras_cv/ (package root)
– api/      ← public Python API entrypoints
– src/      ← implementation code (organized by submodules: backend abstraction, layers, models, datasets, metrics, losses, custom ops, utils, training, visualization, tests, tools)
- examples/   ← usage snippets / demos
- benchmarks/ ← performance tests
- build_deps/ ← Bazel-based pip-wheel build config (for custom ops)
- .github/, .kokoro/, WORKSPACE, BUILD.bazel ← CI/CD & build definitions
- setup.py, pyproject.toml, requirements*.txt ← packaging & dependencies
- MVC-like layering:
– API layer (keras_cv/api)
– Core implementation (keras_cv/src)
– Backend adapters (tensorflow, JAX, PyTorch abstraction in src/backend)
– Extensions: custom C++ ops built via Bazel under src/custom_ops
– Utilities & tools for weight conversion, training scripts, and resource loading
- CI pipelines: GitHub workflows + Kokoro configs handle tests, nightly builds, custom-ops wheel builds.

##### README for additional insights
- Multi-backend support: configured via KERAS_BACKEND
- Highlights major modules: layers, metrics, callbacks, models, datasets
- Provides instructions for custom-op builds via Bazel
- Emphasizes extension points: adding backbones, meta-architectures, new tasks

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Applications
    subgraph "User Applications"
        Examples["Examples & Demos"]:::python
        Benchmarks["Benchmarks"]:::python
    end

    %% Public API Layer
    API["Public API Layer"]:::python

    %% Core Implementation
    subgraph "Core Implementation"
        subgraph "Layers"
            Layers["Layers"]:::python
        end
        subgraph "Models"
            Models["Models"]:::python
        end
        subgraph "Datasets"
            Datasets["Datasets"]:::python
        end
        subgraph "Losses & Metrics"
            Losses["Losses"]:::python
            Metrics["Metrics"]:::python
        end
        subgraph "Callbacks & Visualization"
            Callbacks["Callbacks"]:::python
            Visualization["Visualization"]:::python
        end
        subgraph "Training & Utils"
            Training["Training Utilities"]:::python
            Utils["Core Utilities & Presets"]:::python
        end
    end

    %% Adapter Layer
    Backend["Backend Adapters"]:::adapter

    %% Native Framework Runtimes
    subgraph "Native Runtimes"
        TF["TensorFlow"]:::external
        JAX["JAX"]:::external
        Torch["PyTorch"]:::external
    end

    %% Custom Ops & Build
    CustomOps["Custom Ops (C++ Kernels)"]:::build
    BuildSys["Build & Packaging"]:::build

    %% CI/CD
    subgraph "CI/CD"
        GH["GitHub Actions"]:::ci
        Kokoro["Kokoro"]:::ci
    end

    %% Relationships
    Examples -->|uses API| API
    Benchmarks -->|uses API| API

    API --> Layers
    API --> Models
    API --> Datasets
    API --> Losses
    API --> Metrics
    API --> Callbacks
    API --> Visualization
    API --> Training
    API --> Utils

    Layers --> Backend
    Models --> Backend
    Datasets --> Backend
    Losses --> Backend
    Metrics --> Backend
    Callbacks --> Backend
    Visualization --> Backend
    Training --> Backend
    Utils --> Backend

    Backend --> TF
    Backend --> JAX
    Backend --> Torch

    Layers -->|requires| CustomOps
    CustomOps --> Backend

    GH --> BuildSys
    Kokoro --> BuildSys
    BuildSys --> CustomOps

    %% Click Events
    click Examples "https://github.com/keras-team/keras-cv/tree/master/examples/"
    click Benchmarks "https://github.com/keras-team/keras-cv/tree/master/benchmarks/"
    click API "https://github.com/keras-team/keras-cv/tree/master/keras_cv/api/"
    click Layers "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/layers/"
    click Models "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/models/"
    click Datasets "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/datasets/"
    click Losses "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/losses/"
    click Metrics "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/metrics/"
    click Callbacks "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/callbacks/"
    click Visualization "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/visualization/"
    click Training "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/training/"
    click Utils "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/utils/"
    click Backend "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/backend/"
    click CustomOps "https://github.com/keras-team/keras-cv/tree/master/keras_cv/src/custom_ops/"
    click BuildSys "https://github.com/keras-team/keras-cv/tree/master/build_deps/"
    click GH "https://github.com/keras-team/keras-cv/tree/master/.github/workflows/"
    click Kokoro "https://github.com/keras-team/keras-cv/tree/master/.kokoro/"

    %% Styles
    classDef python fill:#bbdefb,stroke:#000
    classDef adapter fill:#c8e6c9,stroke:#000
    classDef external fill:#ffcdd2,stroke:#000
    classDef build fill:#eeeeee,stroke:#000
    classDef ci fill:#fff9c4,stroke:#000
```
