# wongzbb/metateacher architecture

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

- Interactive diagram: https://gitdiagram.com/wongzbb/metateacher
- Repository: https://github.com/wongzbb/metateacher

## Overview

##### Project type and purpose
- This is a research‐oriented PyTorch implementation of “MetaTeacher,” a multi‐model domain‐adaptation pipeline for medical image classification.
- It trains one or more teacher networks (e.g., ResNet, DenseNet) and coordinates their knowledge to guide a smaller student network via specialized loss functions.

##### File structure
- Top‐level scripts:
- train.py         – main training entry point (coordinated domain adaptation).
- train_source.py  – source‐only pre‐training.
- data_list.py     – dataset definitions and splits.
- loss.py          – overall loss orchestrator.
- metric/loss.py   – custom metric‐based losses (e.g., domain discrepancy).
- Core packages:
- models/          – definition of all model classes.
– embedding.py   – shared feature embedder.
– student/       – small student network variants (lenet, mynet, fcnet, etc.).
– teacher/       – large teacher network variants (ResNet, VGG, AlexNet, etc.) and hint modules.

##### README for additional insights
- Confirms multi‐model “MetaTeacher” approach.
- Points to the NeurIPS paper for algorithmic details.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Pipeline
    subgraph "Data Pipeline" 
        DP["Data Pipeline\ndata_list.py"]:::data
    end
    click DP "https://github.com/wongzbb/metateacher/blob/main/data_list.py"

    %% Scripts
    subgraph "Training Scripts"
        source["Source-only Pre-training\ntrain_source.py"]:::data
        meta["MetaTeacher Adaptation\ntrain.py"]:::data
    end
    click source "https://github.com/wongzbb/metateacher/blob/main/train_source.py"
    click meta "https://github.com/wongzbb/metateacher/blob/main/train.py"

    %% Model Components
    subgraph "Model Components"
        embed["Shared Embedder\nmodels/embedding.py"]:::model

        subgraph "Teacher Ensemble"
            alex["AlexNet"]:::model
            densenet["DenseNet"]:::model
            dpn["DPN"]:::model
            googlenet["GoogleNet"]:::model
            preact["PreAct ResNet"]:::model
            resnet["ResNet Variants"]:::model
            vgg["VGG"]:::model
            hint["Hint Modules"]:::model
        end

        subgraph "Student Networks"
            lenet["LeNet"]:::model
            mynet["MyNet"]:::model
            fcnet["FCNet"]:::model
            resnets["ResNet_s"]:::model
        end
    end
    click embed "https://github.com/wongzbb/metateacher/blob/main/models/embedding.py"
    click alex "https://github.com/wongzbb/metateacher/blob/main/models/teacher/alexnet.py"
    click densenet "https://github.com/wongzbb/metateacher/blob/main/models/teacher/densenet.py"
    click dpn "https://github.com/wongzbb/metateacher/blob/main/models/teacher/dpn.py"
    click googlenet "https://github.com/wongzbb/metateacher/blob/main/models/teacher/googlenet.py"
    click preact "https://github.com/wongzbb/metateacher/blob/main/models/teacher/preact_resnet.py"
    click resnet "https://github.com/wongzbb/metateacher/blob/main/models/teacher/resnet.py"
    click vgg "https://github.com/wongzbb/metateacher/blob/main/models/teacher/vgg.py"
    click hint "https://github.com/wongzbb/metateacher/blob/main/models/teacher/hint.py"
    click lenet "https://github.com/wongzbb/metateacher/blob/main/models/student/lenet.py"
    click mynet "https://github.com/wongzbb/metateacher/blob/main/models/student/mynet.py"
    click fcnet "https://github.com/wongzbb/metateacher/blob/main/models/student/fcnet.py"
    click resnets "https://github.com/wongzbb/metateacher/blob/main/models/student/resnet_s.py"

    %% Loss & Adaptation
    subgraph "Loss & Adaptation Coordinator"
        losscoord["Adaptation Coordinator\nloss.py"]:::loss
        domain["Domain Discrepancy Loss\nmetric/loss.py"]:::loss
    end
    click losscoord "https://github.com/wongzbb/metateacher/blob/main/loss.py"
    click domain "https://github.com/wongzbb/metateacher/blob/main/metric/loss.py"

    %% Utilities
    subgraph "Utilities"
        avg["AverageMeter\nutils/averagemeter.py"]:::utils
        shape["Shape Helpers\nutils/feature_shape.py"]:::utils
        init["Model Init\nutils/model_init.py"]:::utils
    end
    click avg "https://github.com/wongzbb/metateacher/blob/main/utils/averagemeter.py"
    click shape "https://github.com/wongzbb/metateacher/blob/main/utils/feature_shape.py"
    click init "https://github.com/wongzbb/metateacher/blob/main/utils/model_init.py"

    %% Evaluation & Metrics
    subgraph "Evaluation & Metrics"
        eval["Evaluation Loop\ntrain.py"]:::data
        metrics["Accuracy & Discrepancy\nmetric/loss.py"]:::loss
    end

    %% Connections
    DP --> source
    DP --> meta
    DP --> embed
    DP --> alex
    DP --> lenet

    embed --> alex
    embed --> lenet

    alex --> losscoord
    densenet --> losscoord
    dpn --> losscoord
    googlenet --> losscoord
    preact --> losscoord
    resnet --> losscoord
    vgg --> losscoord
    hint --> losscoord

    lenet --> losscoord
    mynet --> losscoord
    fcnet --> losscoord
    resnets --> losscoord

    domain --> losscoord

    losscoord --> meta
    meta --> avg
    meta --> shape
    meta --> init

    meta --> eval
    eval --> metrics

    %% Styles
    classDef data fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef model fill:#90EE90,stroke:#333,stroke-width:1px
    classDef loss fill:#FFA500,stroke:#333,stroke-width:1px
    classDef utils fill:#D3D3D3,stroke:#333,stroke-width:1px
```
