How artanic30/hoiclip works
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 Epoch engine · main.py Training CLI · hoiclip.py HOICLIP detector · hico.py HICO-DET dataset
Components 18
Runtime
- Distributed launch · Multi-GPU training and evaluation profiles.
scripts/train_hico.sh - Training CLI · Selects task, builds data and model, and starts execution.
main.py - Epoch engine · Runs optimization, inference, evaluation, and enhancement.
engine.py - Postprocessing · Applies box operations, filtering, and top-k result selection.
util/topk.py - Outputs & checkpoints · Stores checkpoints, predictions, and training-free enhancement results.
Data & evaluation
- HICO-DET dataset · Loads HICO images, annotations, mappings, and transforms.
datasets/datasets_gen/hico.py - V-COCO dataset · Loads V-COCO images, annotations, mappings, and transforms.
datasets/datasets_gen/vcoco.py - HOI text labels · Dataset-specific CLIP text labels.
datasets/hico_text_label.py - Task evaluators · Formats and scores HICO-DET or V-COCO predictions.
datasets/datasets_gen/hico_eval.py - Feature datasets · Supports CLIP-derived and SWIG feature generation.
datasets/datasets_generate_feature/hico.py
Detector & CLIP
- Model assembly · Selects the detector implementation.
models/__init__.py - HOICLIP detector · Query detector predicting human/object boxes, objects, and interactions.
models/models_hoiclip/hoiclip.py - Backbone & position · ResNet visual features and positional encoding for transformer detection.
models/backbone.py - Modified CLIP · Vendored image/text encoder used for label supervision or scoring.
ModifiedCLIP/clip.py - HOI matcher · Matches query predictions to HOI targets for loss computation.
models/matcher.py
Offline utilities
- DETR weight conversion · Converts upstream DETR weights for two-branch initialization.
tools/convert_parameters.py - Verb embedding generation · Produces .pth verb embedding artifacts from image features.
models/generate_image_feature/generate_verb.py - Evaluation conversion · Converts V-COCO annotations or HICO predictions for external evaluation.
tools/convert_vcoco_annotations.py
Connections 23
- 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