# artanic30/hoiclip architecture

> Architecture diagram of the GitHub repository artanic30/hoiclip, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/artanic30/hoiclip
- Repository: https://github.com/artanic30/hoiclip

## Overview

#### Purpose and entry points
HOICLIP is a PyTorch research system for human–object interaction (HOI) detection, transferring CLIP vision-language knowledge into a DETR-style detector. `main.py` is the training/evaluation entry point; `engine.py` owns epoch-level optimization, inference, evaluation, and training-free enhancement. Shell launch profiles are under `scripts/train_hico.sh` and `scripts/train_vcoco.sh`.

#### Runtime and execution model
The primary runtime is Python/PyTorch, launched with `torch.distributed.launch` for multi-GPU distributed training/evaluation. It consumes externally prepared HICO-DET or V-COCO datasets, DETR-pretrained ResNet-50 weights, and optionally downloaded HOICLIP checkpoints. Dependencies are declared in `requirements.txt`.

#### Dataset ingestion and task variants
Dataset selection flows from CLI arguments in `main.py` into dataset builders and evaluators for HICO-DET or V-COCO. These layers load images, HOI annotations, object/verb/HOI label mappings, transforms, and dataset-specific evaluation formats:
- `datasets/datasets_gen/hico.py`
- `datasets/datasets_gen/vcoco.py`
- `datasets/datasets_gen/hico_eval.py`
- `datasets/datasets_gen/vcoco_eval.py`

A parallel feature-generation dataset family supports generating CLIP-derived image/verb representations, including SWIG-related data: `datasets/datasets_generate_feature/`.

#### HOI detector construction
Model assembly is selected through `models/__init__.py` and the generation-oriented model implementations. The main HOICLIP architecture combines a ResNet backbone, positional encoding, transformer/query-based detection, and HOI heads that predict human/object boxes, object classes, and verb/interaction scores:
- `models/models_hoiclip/hoiclip.py`
- `models/models_hoiclip/gen.py`
- `models/backbone.py`
- `models/position_encoding.py`

The repository also retains GEN-VLKT-oriented implementations, likely as alternative or inherited model paths: `models/models_gen/gen.py` and `models/models_gen/gen_vlkt.py`.

#### Vision-language knowledge boundary
A vendored, modified CLIP implementation provides image/text encoders, tokenizer, model definitions, and BPE vocabulary. HOICLIP’s detector model consumes this visual-linguistic representation for CLIP-label supervision or scoring controlled by runtime flags such as `with_clip_label` and `with_obj_clip_label`:
- `ModifiedCLIP/clip.py`
- `ModifiedCLIP/model.py`
- `ModifiedCLIP/simple_tokenizer.py`

Text-label definitions reside at the dataset boundary, including `datasets/hico_text_label.py` and `datasets/vcoco_text_label.py`.

#### Training, matching, and inference flow
For each batch, datasets produce transformed images and HOI targets; the assembled detector emits query-level predictions; matching assigns predictions to targets; losses are optimized in the engine. During evaluation, predictions pass through dataset evaluators and optional NMS filtering. Training-free enhancement writes top-k-derived results beneath the output directory:
- `engine.py`
- `models/matcher.py`
- `util/box_ops.py`
- `util/topk.py`

#### Artifacts and offline utilities
`tools/convert_parameters.py` converts upstream DETR weights into the detector’s two-branch initialization format. V-COCO annotations require an external V-COCO repository and a Python 2 conversion step via `tools/convert_vcoco_annotations.py`. Generated verb embeddings are produced by `models/generate_image_feature/generate_verb.py` and stored as `.pth` artifacts (for example `tmp/verb.pth`). Official HICO prediction conversion is handled by `tools/covert_annot_for_official_eval.py`.

Main entry points: [`engine.py`](https://github.com/artanic30/hoiclip/blob/main/engine.py) (Epoch engine), [`main.py`](https://github.com/artanic30/hoiclip/blob/main/main.py) (Training CLI), [`models/models_hoiclip/hoiclip.py`](https://github.com/artanic30/hoiclip/blob/main/models/models_hoiclip/hoiclip.py) (HOICLIP detector), [`datasets/datasets_gen/hico.py`](https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_gen/hico.py) (HICO-DET dataset)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_launch["Distributed launch<br/>shell profile<br/>[train_hico.sh]"]
  node_main["Training CLI<br/>Python entry point<br/>[main.py]"]
  node_engine["Epoch engine<br/>training loop<br/>[engine.py]"]
  node_postprocess["Postprocessing<br/>box and top-k ops<br/>[topk.py]"]
  node_artifacts[("Outputs &amp; checkpoints<br/>artifact storage")]
end

subgraph group_data["Data &amp; evaluation"]
  node_hico_data[("HICO-DET dataset<br/>dataset builder<br/>[hico.py]")]
  node_vcoco_data[("V-COCO dataset<br/>dataset builder<br/>[vcoco.py]")]
  node_text_labels["HOI text labels<br/>label definitions<br/>[hico_text_label.py]"]
  node_evaluators["Task evaluators<br/>evaluation adapter<br/>[hico_eval.py]"]
  node_feature_data[("Feature datasets<br/>generation dataset<br/>[hico.py]")]
end

subgraph group_model["Detector &amp; CLIP"]
  node_model_factory["Model assembly<br/>model factory<br/>[__init__.py]"]
  node_hoiclip["HOICLIP detector<br/>HOI detector<br/>[hoiclip.py]"]
  node_detr_layers["Backbone &amp; position<br/>detector layers<br/>[backbone.py]"]
  node_clip["Modified CLIP<br/>vision-language encoder<br/>[clip.py]"]
  node_matcher["HOI matcher<br/>assignment<br/>[matcher.py]"]
end

subgraph group_utilities["Offline utilities"]
  node_weight_convert["DETR weight conversion<br/>conversion utility"]
  node_verb_features["Verb embedding generation<br/>feature utility<br/>[generate_verb.py]"]
  node_annotation_convert["Evaluation conversion<br/>annotation utility"]
end

node_launch -->|"launches"| node_main
node_main -->|"selects"| node_hico_data
node_main -->|"selects"| node_vcoco_data
node_main -->|"builds"| node_model_factory
node_main -->|"runs"| node_engine
node_hico_data -->|"uses"| node_text_labels
node_vcoco_data -->|"uses"| node_text_labels
node_model_factory -->|"constructs"| node_hoiclip
node_hoiclip -->|"uses"| node_detr_layers
node_hoiclip -->|"uses CLIP features"| node_clip
node_text_labels -->|"defines text prompts"| node_clip
node_hico_data -->|"batches and targets"| node_engine
node_vcoco_data -->|"batches and targets"| node_engine
node_engine -->|"forward pass"| node_hoiclip
node_engine -->|"assigns targets"| node_matcher
node_engine -->|"filters predictions"| node_postprocess
node_postprocess -->|"evaluation predictions"| node_evaluators
node_evaluators -->|"metrics and results"| node_artifacts
node_engine -->|"checkpoints and enhancement"| node_artifacts
node_weight_convert -.->|"initializes weights"| node_hoiclip
node_feature_data -->|"generation inputs"| node_verb_features
node_verb_features -->|"verb .pth files"| node_artifacts
node_annotation_convert -.->|"external evaluation format"| node_evaluators

click node_launch "https://github.com/artanic30/hoiclip/blob/main/scripts/train_hico.sh"
click node_main "https://github.com/artanic30/hoiclip/blob/main/main.py"
click node_engine "https://github.com/artanic30/hoiclip/blob/main/engine.py"
click node_hico_data "https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_gen/hico.py"
click node_vcoco_data "https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_gen/vcoco.py"
click node_text_labels "https://github.com/artanic30/hoiclip/blob/main/datasets/hico_text_label.py"
click node_evaluators "https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_gen/hico_eval.py"
click node_feature_data "https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_generate_feature/hico.py"
click node_model_factory "https://github.com/artanic30/hoiclip/blob/main/models/__init__.py"
click node_hoiclip "https://github.com/artanic30/hoiclip/blob/main/models/models_hoiclip/hoiclip.py"
click node_detr_layers "https://github.com/artanic30/hoiclip/blob/main/models/backbone.py"
click node_clip "https://github.com/artanic30/hoiclip/blob/main/ModifiedCLIP/clip.py"
click node_matcher "https://github.com/artanic30/hoiclip/blob/main/models/matcher.py"
click node_postprocess "https://github.com/artanic30/hoiclip/blob/main/util/topk.py"
click node_weight_convert "https://github.com/artanic30/hoiclip/blob/main/tools/convert_parameters.py"
click node_verb_features "https://github.com/artanic30/hoiclip/blob/main/models/generate_image_feature/generate_verb.py"
click node_annotation_convert "https://github.com/artanic30/hoiclip/blob/main/tools/convert_vcoco_annotations.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_launch,node_main,node_engine,node_postprocess,node_artifacts toneBlue
class node_hico_data,node_vcoco_data,node_text_labels,node_evaluators,node_feature_data toneAmber
class node_model_factory,node_hoiclip,node_detr_layers,node_clip,node_matcher toneMint
class node_weight_convert,node_verb_features,node_annotation_convert toneRose
```

## Components

### Runtime

- [Distributed launch](https://github.com/artanic30/hoiclip/blob/main/scripts/train_hico.sh): shell profile · Multi-GPU training and evaluation profiles. · `scripts/train_hico.sh`
- [Training CLI](https://github.com/artanic30/hoiclip/blob/main/main.py): Python entry point · Selects task, builds data and model, and starts execution. · `main.py`
- [Epoch engine](https://github.com/artanic30/hoiclip/blob/main/engine.py): training loop · Runs optimization, inference, evaluation, and enhancement. · `engine.py`
- [Postprocessing](https://github.com/artanic30/hoiclip/blob/main/util/topk.py): box and top-k ops · Applies box operations, filtering, and top-k result selection. · `util/topk.py`
- **Outputs & checkpoints**: artifact storage · Stores checkpoints, predictions, and training-free enhancement results.

### Data & evaluation

- [HICO-DET dataset](https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_gen/hico.py): dataset builder · Loads HICO images, annotations, mappings, and transforms. · `datasets/datasets_gen/hico.py`
- [V-COCO dataset](https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_gen/vcoco.py): dataset builder · Loads V-COCO images, annotations, mappings, and transforms. · `datasets/datasets_gen/vcoco.py`
- [HOI text labels](https://github.com/artanic30/hoiclip/blob/main/datasets/hico_text_label.py): label definitions · Dataset-specific CLIP text labels. · `datasets/hico_text_label.py`
- [Task evaluators](https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_gen/hico_eval.py): evaluation adapter · Formats and scores HICO-DET or V-COCO predictions. · `datasets/datasets_gen/hico_eval.py`
- [Feature datasets](https://github.com/artanic30/hoiclip/blob/main/datasets/datasets_generate_feature/hico.py): generation dataset · Supports CLIP-derived and SWIG feature generation. · `datasets/datasets_generate_feature/hico.py`

### Detector & CLIP

- [Model assembly](https://github.com/artanic30/hoiclip/blob/main/models/__init__.py): model factory · Selects the detector implementation. · `models/__init__.py`
- [HOICLIP detector](https://github.com/artanic30/hoiclip/blob/main/models/models_hoiclip/hoiclip.py): HOI detector · Query detector predicting human/object boxes, objects, and interactions. · `models/models_hoiclip/hoiclip.py`
- [Backbone & position](https://github.com/artanic30/hoiclip/blob/main/models/backbone.py): detector layers · ResNet visual features and positional encoding for transformer detection. · `models/backbone.py`
- [Modified CLIP](https://github.com/artanic30/hoiclip/blob/main/ModifiedCLIP/clip.py): vision-language encoder · Vendored image/text encoder used for label supervision or scoring. · `ModifiedCLIP/clip.py`
- [HOI matcher](https://github.com/artanic30/hoiclip/blob/main/models/matcher.py): assignment · Matches query predictions to HOI targets for loss computation. · `models/matcher.py`

### Offline utilities

- [DETR weight conversion](https://github.com/artanic30/hoiclip/blob/main/tools/convert_parameters.py): conversion utility · Converts upstream DETR weights for two-branch initialization. · `tools/convert_parameters.py`
- [Verb embedding generation](https://github.com/artanic30/hoiclip/blob/main/models/generate_image_feature/generate_verb.py): feature utility · Produces .pth verb embedding artifacts from image features. · `models/generate_image_feature/generate_verb.py`
- [Evaluation conversion](https://github.com/artanic30/hoiclip/blob/main/tools/convert_vcoco_annotations.py): annotation utility · Converts V-COCO annotations or HICO predictions for external evaluation. · `tools/convert_vcoco_annotations.py`

## Connections

- Distributed launch → Training CLI: launches
- Training CLI → HICO-DET dataset: selects
- Training CLI → V-COCO dataset: selects
- Training CLI → Model assembly: builds
- Training CLI → Epoch engine: runs
- HICO-DET dataset → HOI text labels: uses
- V-COCO dataset → HOI text labels: uses
- Model assembly → HOICLIP detector: constructs
- HOICLIP detector → Backbone & position: uses
- HOICLIP detector → Modified CLIP: uses CLIP features
- HOI text labels → Modified CLIP: defines text prompts
- HICO-DET dataset → Epoch engine: batches and targets
- V-COCO dataset → Epoch engine: batches and targets
- Epoch engine → HOICLIP detector: forward pass
- Epoch engine → HOI matcher: assigns targets
- Epoch engine → Postprocessing: filters predictions
- Postprocessing → Task evaluators: evaluation predictions
- Task evaluators → Outputs & checkpoints: metrics and results
- Epoch engine → Outputs & checkpoints: checkpoints and enhancement
- DETR weight conversion → HOICLIP detector: initializes weights
- Feature datasets → Verb embedding generation: generation inputs
- Verb embedding generation → Outputs & checkpoints: verb .pth files
- Evaluation conversion → Task evaluators: external evaluation format
