# kheffah/tensorflow_fcn8workflow architecture

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

- Interactive diagram: https://gitdiagram.com/kheffah/tensorflow_fcn8workflow
- Repository: https://github.com/kheffah/tensorflow_fcn8workflow

## Overview

##### Project Type and Overall Purpose
- This project implements a full workflow for fine-scale semantic segmentation using the FCN-8 architecture (with a VGG-16 backbone) in TensorFlow.
- It supports training and multiple prediction modes (test, all, unlabeled) on image datasets.
- The workflow integrates data handling/preprocessing, model definition, training/execution, and output visualization.

##### Top-Level Components
a. Entry Point and Command-Line Interface:
- Main runner (Run.py at the top level) which acts as the central execution controller.
- Additional Scripts/Run.py and Settings files that provide runtime parameters, particularly for sample runs.

b. Data Management and Preprocessing:
- The DataManagement.py file is responsible for managing datasets.
- The sampleRun directory contains the sample input images, preprocessing scripts (sampleRun/preprocess.py), and folders for storing results (sampleRun/results) and other assets.

c. Model Definition and Execution:
- The core model is defined in FCN8VGG16Model.py and run via FCN8VGG16Model_Run.py.
- These modules explain how the FCN8 (fully convolutional network) is built based on the VGG-16 architecture.
- The tensorflow-fcn submodule (included as a git submodule) provides additional building blocks required for model construction and training.

d. Utility and Visualization Components:
- PlottingUtils.py and ProjectUtils.py provide auxiliary functionalities for visualizations and project-specific utilities such as logging and possibly metrics.

e. Environment and Dependency Setup:
- Mention the README instructions for installing all required dependencies (e.g., TensorFlow GPU, numpy, scipy, etc.).
- The FCN-specific libraries, like tensorflow-fcn, are integrated into the workflow.

##### Relationships and Interactions
- Preprocessing (sampleRun/preprocess.py) cleans and prepares the data before feeding it to the model.
- DataManagement.py orchestrates data provisioning for model training and prediction.
- The FCN8VGG16Model.py builds the network architecture by invoking routines from the tensorflow-fcn submodule, possibly loading VGG16 weights (downloaded as described in the README).
- FCN8VGG16Model_Run.py then drives the execution of training/predicting operations.
- Finally, output files (predictions, visualizations) are generated and possibly further processed by PlottingUtils.py.

##### Architectural Patterns and Technologies
- The project follows a modular design where each concern (data management, model building, training execution, result visualization) is encapsulated in its own Python module.
- Use of TensorFlow for building and running the FCN model.
- Leveraging a pre-trained VGG-16 model, the workflow downloads and incorporates the relevant weights.
- The approach shows practices of decoupling functionality: separate modules for data handling, model definition, and execution.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "User/CLI Layer"
        CLI_Runner["Run.py (CLI Entry Point)"]:::cli
        CLI_Scripts["Scripts/Run.py"]:::cli
        RunSettings1["Runtime Settings (Scripts)"]:::cli
        RunSettings2["Runtime Settings (sampleRun)"]:::cli
    end

    subgraph "Data Layer"
        Images["sampleRun/images"]:::data
        DataM["DataManagement.py"]:::data
        Preproc["sampleRun/preprocess.py"]:::data
    end

    subgraph "Model/Service Layer"
        ModelDef["FCN8VGG16Model.py"]:::model
        ModelExec["FCN8VGG16Model_Run.py"]:::model
        TF["TensorFlow FCN (tensorflow-fcn)"]:::model
    end

    subgraph "Output & Visualization Layer"
        VisUtils["PlottingUtils.py"]:::visual
        Results["sampleRun/results"]:::visual
    end

    subgraph "Utilities"
        Utilities["ProjectUtils.py"]:::utility
    end

    %% Flow Connections
    RunSettings1 -->|"settings"| CLI_Runner
    RunSettings2 -->|"settings"| CLI_Scripts

    CLI_Runner -->|"triggers"| DataM
    CLI_Scripts -->|"triggers"| DataM

    Images -->|"raw_data"| DataM
    DataM -->|"provides_data"| Preproc

    Preproc -->|"preprocessed_data"| ModelDef
    ModelDef -->|"builds"| ModelExec
    ModelDef -->|"uses"| TF

    ModelExec -->|"outputs"| VisUtils
    VisUtils -->|"saves"| Results
    ModelExec -->|"logs"| Utilities

    %% Click Events
    click CLI_Runner "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/Run.py"
    click CLI_Scripts "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/Scripts/Run.py"
    click RunSettings1 "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/Scripts/Run_settings.py"
    click RunSettings2 "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/sampleRun/run_script/Run_settings.py"
    click DataM "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/DataManagement.py"
    click Images "https://github.com/kheffah/tensorflow_fcn8workflow/tree/master/sampleRun/images"
    click Preproc "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/sampleRun/preprocess.py"
    click ModelDef "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/FCN8VGG16Model.py"
    click ModelExec "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/FCN8VGG16Model_Run.py"
    click TF "https://github.com/kheffah/tensorflow_fcn8workflow/tree/master/tensorflow-fcn"
    click VisUtils "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/PlottingUtils.py"
    click Results "https://github.com/kheffah/tensorflow_fcn8workflow/tree/master/sampleRun/results"
    click Utilities "https://github.com/kheffah/tensorflow_fcn8workflow/blob/master/ProjectUtils.py"

    %% Class Styles
    classDef cli fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef data fill:#bbf1f6,stroke:#1f78b4,stroke-width:2px;
    classDef model fill:#ffe066,stroke:#ff9f1c,stroke-width:2px;
    classDef visual fill:#caffbf,stroke:#2ca02c,stroke-width:2px;
    classDef utility fill:#ffc6ff,stroke:#d62728,stroke-width:2px;

    class CLI_Runner,CLI_Scripts,RunSettings1,RunSettings2 cli;
    class Images,DataM,Preproc data;
    class ModelDef,ModelExec,TF model;
    class VisUtils,Results visual;
    class Utilities utility;
```
