Giter Site home page Giter Site logo

pysgg-cxg's Introduction

LANDMARK: Language-guided Representation Enhancement Framework for Scene Graph Generation

Python PyTorch

Our paper LANDMARK: Language-guided Representation Enhancement Framework for Scene Graph Generation official code

We also announce a new scene graph branchmark as replacement of scene-graph-brenchmark and PySGG. There are following updating:

  • fix PYSGG bug that always map box.weight to relation.weight, even checkpoint is given (commit 9131f3.. )
  • Add more state of art methods: Dual-Transformer, SHA, C-bias
  • Allowing batch size more than one in test/val phrase (fixed from PySGG).
  • fix truncate image error problem.
  • Allow loading different size weights with same name.
  • Support multi-gpu on SHA model

Installation

Check INSTALL.md for installation instructions.

Dataset

Check DATASET.md for instructions of dataset preprocessing.

Training (IMPORTANT)

Prepare Faster-RCNN Detector

  • You can download the pretrained Faster R-CNN we used in the paper:
  • put the checkpoint into the folder:
mkdir -p checkpoints/detection/pretrained_faster_rcnn/
# for VG
mv /path/vg_faster_det.pth checkpoints/detection/pretrained_faster_rcnn/

Then, you need to modify the pretrained weight parameter MODEL.PRETRAINED_DETECTOR_CKPT in configs yaml configs/bgnn.yaml to the path of corresponding pretrained rcnn weight to make sure you load the detection weight parameter correctly.

LANDMARK framework

You can follow the following instructions to train your own, which takes 2 GPUs for traing. The results should be very close to the reported results given in paper.

LANDMARK framework auguments:

3 paradiagms are enabled following 3 commands:

MODEL.TWO_STAGE_ON True #For EEM
MODEL.ROI_RELATION_HEAD.VISUAL_LANGUAGE_MERGER_EDGE True #For LAM
MODEL.ROI_RELATION_HEAD.VISUAL_LANGUAGE_MERGER_OBJ True  #For LCM

you can copy the following command to train

Scripts

For baseline bgnn, we use configration file configs/bgnn.yaml provided by author:

gpu_num=2 && python -m torch.distributed.launch --master_port 10028 --nproc_per_node=$gpu_num \
       tools/relation_train_net.py \
       --config-file "configs/bgnn.yaml" \
        DEBUG False \
        EXPERIMENT_NAME "human_bgnn" \
        MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor \
        MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \
        MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \
        SOLVER.IMS_PER_BATCH $[10*$gpu_num] \
        TEST.IMS_PER_BATCH $[$gpu_num] \
        SOLVER.VAL_PERIOD 500 \
        SOLVER.CHECKPOINT_PERIOD 500\
        MODEL.PRETRAINED_DETECTOR_CKPT "checkpoints/detection/pretrained_faster_rcnn/vg_faster_det.pth"\
        SOLVER.BASE_LR 0.006 \
        DATALOADER.NUM_WORKERS 0 \
        MODEL.TWO_STAGE_ON True \
        MODEL.TWO_STAGE_HEAD.LOSS_TYPE 'mse_loss' \
        MODEL.ROI_RELATION_HEAD.VISUAL_LANGUAGE_MERGER_EDGE True \
        MODEL.ROI_RELATION_HEAD.VISUAL_LANGUAGE_MERGER_OBJ True \
        
        

For baseline MOTIFs, IMP, G-RCNN, Transformer..., ypu just need to change MODEL.ROI_RELATION_HEAD.PREDICTOR to one of MotifPredictor, IMPPredictor, AGRCNNPredictor,TransformerPredictor:

gpu_num=2 && python -m torch.distributed.launch --master_port 10028 --nproc_per_node=$gpu_num \
       tools/relation_train_net.py \
       --config-file "configs/e2e_relation_X_101_32_8_FPN_1x.yaml" \
        DEBUG False \
        EXPERIMENT_NAME "human_motif" \
        MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \
        MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \
        MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \
        SOLVER.IMS_PER_BATCH $[6*$gpu_num] \
        TEST.IMS_PER_BATCH $[$gpu_num] \
        SOLVER.VAL_PERIOD 500 \
        SOLVER.CHECKPOINT_PERIOD 500\
        MODEL.PRETRAINED_DETECTOR_CKPT "checkpoints/detection/pretrained_faster_rcnn/vg_faster_det.pth"\
        SOLVER.BASE_LR 0.02 \
        DATALOADER.NUM_WORKERS 0 \
        MODEL.TWO_STAGE_ON True \
        MODEL.TWO_STAGE_HEAD.LOSS_TYPE 'mse_loss' \
        MODEL.ROI_RELATION_HEAD.VISUAL_LANGUAGE_MERGER_EDGE True \
        MODEL.ROI_RELATION_HEAD.VISUAL_LANGUAGE_MERGER_OBJ True \
        
        

For baseline Unbiasd, all you need to do is set those :

MODEL.ROI_RELATION_HEAD.PREDICTOR CausalAnalysisPredictor \
MODEL.ROI_RELATION_HEAD.CAUSAL.AUXILIARY_LOSS True \
MODEL.ROI_RELATION_HEAD.CAUSAL.CONTEXT_LAYER bgnn #or motifs \
MODEL.ROI_RELATION_HEAD.CAUSAL.EFFECT_ANALYSIS True \
MODEL.ROI_RELATION_HEAD.CAUSAL.EFFECT_TYPE TDE \

Test

You can directly check performance of model from the checkpoint. By replacing the parameter of MODEL.WEIGHT to the trained model weight and selected dataset name in DATASETS.TEST, you can directly eval the model on validation or test set.

archive_dir="checkpoints/predcls-BGNNPredictor/xxx/xxx"

python -m torch.distributed.launch --master_port 10029 --nproc_per_node=$gpu_num  \
  tools/relation_test_net.py \
  --config-file "$archive_dir/config.yml"\
    TEST.IMS_PER_BATCH $[$gpu_num] \
   MODEL.WEIGHT  "$archive_dir/model_xxx.pth"\
   MODEL.ROI_RELATION_HEAD.EVALUATE_REL_PROPOSAL False \
   DATASETS.TEST "('VG_stanford_filtered_with_attribute_eval', )"

visiualization

Firstly, you need prepare eval_results.pytorch and visual_info.json generated by relation_test_net.py. Then, change detected_origin_path your results path. You can get image with predicted box and predicted relation in output stream by:

python visualization/visualize_PredCls_and_SGCls.py --detected_origin_path <your path/> --start_idx 0 --end_idx 100 --draw_pred_box True --draw_gt_box False 

Citations

If you find this project helps your research, please kindly consider citing our papers in your publications.

@misc{chang2023landmark,
      title={LANDMARK: Language-guided Representation Enhancement Framework for Scene Graph Generation}, 
      author={Xiaoguang Chang and Teng Wang and Shaowei Cai and Changyin Sun},
      year={2023},
      eprint={2303.01080},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

Acknowledgment

This repository is developed on top of the scene graph benchmark Toolkit PySGG

pysgg-cxg's People

Contributors

rafa-cxg avatar

Stargazers

 avatar Monesh avatar  avatar  avatar Maëlic Neau avatar  avatar Fantastic avatar Zhanwen Chen avatar Hongyeob Kim avatar  avatar Leilei Ma avatar  avatar

Watchers

James Cloos avatar  avatar

Forkers

zhanwenchen

pysgg-cxg's Issues

KeyError:"image_paths"

I'm very interested in your work, but I'm having a problem reproducing your code.
/20 19:37:22 pysgg]: #################### end load checkpointer ####################
[06/20 19:37:22 pysgg]: #################### Start initializing dataset & dataloader ####################
[06/20 19:37:24 dataset]: using resampling method:bilvl
[06/20 19:37:24 dataset]: load repeat_dict from checkpoints/sgdet-BGNNPredictor/human_bgnn/repeat_dict.pkl
[06/20 19:37:24 dataset]: using resampling method:bilvl
[06/20 19:37:24 dataset]: load repeat_dict from checkpoints/sgdet-BGNNPredictor/human_bgnn/repeat_dict.pkl
[06/20 19:37:24 utils.miscellaneous]: Saving labels mapping into checkpoints/sgdet-BGNNPredictor/human_bgnn/labels.json
[06/20 19:37:25 dataset]: using resampling method:bilvl
[06/20 19:37:25 dataset]: load repeat_dict from checkpoints/sgdet-BGNNPredictor/human_bgnn/repeat_dict.pkl
[06/20 19:37:25 dataset]: using resampling method:bilvl
[06/20 19:37:25 dataset]: load repeat_dict from checkpoints/sgdet-BGNNPredictor/human_bgnn/repeat_dict.pkl
[06/20 19:37:25 utils.miscellaneous]: Saving labels mapping into checkpoints/sgdet-BGNNPredictor/human_bgnn/labels.json
[06/20 19:37:26 pysgg]: #################### end dataloader ####################
[06/20 19:37:26 pysgg]: #################### end distributed ####################
[06/20 19:37:26 pysgg]: Start preclser_relpn_pretrain
[06/20 19:37:26 pysgg]: Start training
Traceback (most recent call last):
File "tools/relation_train_net.py", line 822, in
main()
File "tools/relation_train_net.py", line 812, in main
model = train(cfg, args.local_rank, args.distributed, logger)
File "tools/relation_train_net.py", line 430, in train
loss_dict = model(images, targets, logger=logger) #predcls:dict:4
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
Traceback (most recent call last):
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 447, in forward
File "tools/relation_train_net.py", line 822, in
output = self.module(*inputs[0], **kwargs[0])
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/apex-0.1-py3.7-linux-x86_64.egg/apex/amp/_initialize.py", line 197, in new_fwd
main()
File "tools/relation_train_net.py", line 812, in main
**applier(kwargs, input_caster))
File "/home/pysgg/modeling/detector/generalized_rcnn.py", line 53, in forward
x, result, detector_losses = self.roi_heads(features, proposals, targets, logger)#CombinedROIHeads proposals:在100的基础上再加gt
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
model = train(cfg, args.local_rank, args.distributed, logger)
result = self.forward(*input, **kwargs)
File "tools/relation_train_net.py", line 430, in train
File "/home/pysgg/modeling/roi_heads/roi_heads.py", line 79, in forward
x, detections, loss_relation = self.relation(features=features, proposal=detections, targets=targets, logger=logger,**sampling)#ROIRelationHead:在这里proposal被采样.x:roi_feature[all_prop,4096]. detections:proposal
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
loss_dict = model(images, targets, logger=logger) #predcls:dict:4
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/pysgg/modeling/roi_heads/relation_head/relation_head.py", line 233, in forward
result = self.forward(*input, **kwargs)
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/parallel/distributed.py", line 447, in forward
union_features = self.union_feature_extractor(features, proposals,targets, rel_pair_idxs)#union包括所有的N!组合
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
output = self.module(*inputs[0], **kwargs[0])
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home/pysgg/modeling/roi_heads/relation_head/roi_relation_feature_extractors.py", line 143, in forward
result = self.forward(*input, **kwargs)
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/apex-0.1-py3.7-linux-x86_64.egg/apex/amp/_initialize.py", line 197, in new_fwd
**applier(kwargs, input_caster))
File "/home/pysgg/modeling/detector/generalized_rcnn.py", line 53, in forward
img_path = targets[0].get_field('image_paths')
File "/home//pysgg/structures/bounding_box.py", line 53, in get_field
x, result, detector_losses = self.roi_heads(features, proposals, targets, logger)#CombinedROIHeads proposals:在100的基础上再加gt
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
return self.extra_fields[field]
KeyError: 'image_paths'
result = self.forward(*input, **kwargs)
File "/home/wyz/pysgg/modeling/roi_heads/roi_heads.py", line 79, in forward
x, detections, loss_relation = self.relation(features=features, proposal=detections, targets=targets, logger=logger,**sampling)#ROIRelationHead:在这里proposal被采样.x:roi_feature[all_prop,4096]. detections:proposal
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home//pysgg/modeling/roi_heads/relation_head/relation_head.py", line 233, in forward
union_features = self.union_feature_extractor(features, proposals,targets, rel_pair_idxs)#union包括所有的N!组合
File "/home/anaconda3/envs/sgg/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call
result = self.forward(*input, **kwargs)
File "/home//pysgg/modeling/roi_heads/relation_head/roi_relation_feature_extractors.py", line 143, in forward
img_path = targets[0].get_field('image_paths')
File "/home//pysgg/structures/bounding_box.py", line 53, in get_field
return self.extra_fields[field]
KeyError: 'image_paths'
Have you encountered this problem, I will be very grateful if you solve this.
Thanks you!

ModuleNotFoundError: No module named 'pysgg.modeling.roi_heads.relation_head.RTPB.utils'

您好,我对您的工作非常感兴趣,但是我在运行您的程序的时候报错了,
raceback (most recent call last):
File "tools/relation_train_net.py", line 28, in
from pysgg.modeling.detector import build_detection_model
File "/home/wangyize/PySGG/pysgg/modeling/detector/init.py", line 2, in
from .detectors import build_detection_model
File "/home/wangyize/PySGG/pysgg/modeling/detector/detectors.py", line 2, in
from .generalized_rcnn import GeneralizedRCNN
File "/home/wangyize/PySGG/pysgg/modeling/detector/generalized_rcnn.py", line 13, in
from pysgg.modeling.detector import build_detection_model
File "/home/wangyize/PySGG/pysgg/modeling/detector/init.py", line 2, in
from ..roi_heads.roi_heads import build_roi_heads
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/roi_heads.py", line 8, in
from .detectors import build_detection_model
File "/home/wangyize/PySGG/pysgg/modeling/detector/detectors.py", line 2, in
from .relation_head.relation_head import build_roi_relation_head
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/relation_head/relation_head.py", line 18, in
from .generalized_rcnn import GeneralizedRCNN
File "/home/wangyize/PySGG/pysgg/modeling/detector/generalized_rcnn.py", line 13, in
from ..roi_heads.roi_heads import build_roi_heads
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/roi_heads.py", line 8, in
from .roi_relation_predictors import make_roi_relation_predictor
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/relation_head/roi_relation_predictors.py", line 44, in
from .relation_head.relation_head import build_roi_relation_head
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/relation_head/relation_head.py", line 18, in
from .RTPB.bias_module import build_bias_module
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/relation_head/RTPB/bias_module.py", line 5, in
from .roi_relation_predictors import make_roi_relation_predictorfrom .utils import load_data
ModuleNotFoundError: No module named 'pysgg.modeling.roi_heads.relation_head.RTPB.utils'
Traceback (most recent call last):
File "tools/relation_train_net.py", line 28, in
from pysgg.modeling.detector import build_detection_model
File "/home/wangyize/PySGG/pysgg/modeling/detector/init.py", line 2, in
from .detectors import build_detection_model
File "/home/wangyize/PySGG/pysgg/modeling/detector/detectors.py", line 2, in
from .generalized_rcnn import GeneralizedRCNN
File "/home/wangyize/PySGG/pysgg/modeling/detector/generalized_rcnn.py", line 13, in
from ..roi_heads.roi_heads import build_roi_heads
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/roi_heads.py", line 8, in
from .relation_head.relation_head import build_roi_relation_head
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/relation_head/relation_head.py", line 18, in
from .roi_relation_predictors import make_roi_relation_predictor
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/relation_head/roi_relation_predictors.py", line 48, in
from .model_Hybrid_Attention import SHA_Context
File "/home/wangyize/PySGG/pysgg/modeling/roi_heads/relation_head/model_Hybrid_Attention.py", line 6, in
from pysgg.modeling.roi_heads.relation_head.SHA.utils_co_attention import Self_Attention_Encoder, Cross_Attention_Encoder
ModuleNotFoundError: No module named 'pysgg.modeling.roi_heads.relation_head.SHA.utils_co_attention'
根据报错我找不到对应的 utils文件和co_attention'文件,请问您能解决吗
非常感谢

your e-mail?

Hello, I'm concerned from the PENET issue that you are also following this project, may I ask if we can have some communication about the reproduction situation. In addition, I noticed your recent article LANDMARK, this work gives me great inspiration, I hope to communicate with you, can you leave your e-mail?

BACKBONE with VGG16

I want to ask, in the table1 experiment, how did the code implement BACKBONE into VGG16 network?
Should I replace the CONV_BODY attribute in the yaml file and retrain?
1111

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.