├── Prototype-based Graph Information Bottleneck ├── Configures.py ├── README.md ├── image_architecture.jpg ├── load_dataset.py ├── models │ ├── GAT.py │ ├── GCN.py │ ├── GIN.py │ ├── __init__.py │ └── train_gnns.py ├── my_mcts.py ├── proto_join.py └── utils.py ├── README.md └── Self-Training Framework for Scene Graph Generation ├── .gitignore ├── DATASET.md ├── Figure.png ├── INSTALL.md ├── MODEL.md ├── README.md ├── configs ├── evaluation_config │ ├── bgnn_itrans_stsgg_sgdet_eval.yml │ ├── bgnn_stsgg_predcls_eval.yml │ ├── bgnn_stsgg_sgcls_eval.yml │ ├── bgnn_stsgg_sgdet_eval.yml │ ├── hetsgg_stsgg_sgcls_eval.yml │ ├── hetsgg_stsgg_sgdet_eval.yml │ ├── motif_stsgg_predcls_eval.yml │ ├── motif_stsgg_sgcls_eval.yml │ └── motif_stsgg_sgdet_eval.yml ├── sup-50.yaml ├── wsup-1000.yaml ├── wsup-1000_external.yaml ├── wsup-50.yaml ├── wsup-50_external.yaml └── wsup-50_internal.yaml ├── datasets └── vg │ └── 50 │ └── Category_Type_Info.json ├── initial_data └── obj_pred_info │ └── obj_pred_info_50 ├── maskrcnn_benchmark ├── __init__.py ├── config │ ├── __init__.py │ ├── defaults.py │ └── paths_catalog.py ├── csrc │ ├── ROIAlign.h │ ├── ROIPool.h │ ├── SigmoidFocalLoss.h │ ├── cpu │ │ ├── ROIAlign_cpu.cpp │ │ ├── nms_cpu.cpp │ │ └── vision.h │ ├── cuda │ │ ├── ROIAlign_cuda.cu │ │ ├── ROIPool_cuda.cu │ │ ├── SigmoidFocalLoss_cuda.cu │ │ ├── deform_conv_cuda.cu │ │ ├── deform_conv_kernel_cuda.cu │ │ ├── deform_pool_cuda.cu │ │ ├── deform_pool_kernel_cuda.cu │ │ ├── nms.cu │ │ └── vision.h │ ├── deform_conv.h │ ├── deform_pool.h │ ├── nms.h │ └── vision.cpp ├── data │ ├── README.md │ ├── __init__.py │ ├── build.py │ ├── collate_batch.py │ ├── datasets │ │ ├── __init__.py │ │ ├── bi_lvl_rsmp.py │ │ ├── coco.py │ │ ├── concat_dataset.py │ │ ├── evaluation │ │ │ ├── __init__.py │ │ │ ├── coco │ │ │ │ ├── __init__.py │ │ │ │ └── coco_eval.py │ │ │ ├── vg │ │ │ │ ├── __init__.py │ │ │ │ ├── sgg_eval.py │ │ │ │ ├── vg_capgraphs_anno.json │ │ │ │ ├── vg_eval.py │ │ │ │ ├── vg_test_capgraph_anno.json │ │ │ │ ├── vg_test_caption_anno.json │ │ │ │ ├── zeroshot_triplet.pytorch20 │ │ │ │ └── zeroshot_triplet.pytorch50 │ │ │ └── voc │ │ │ │ ├── __init__.py │ │ │ │ └── voc_eval.py │ │ ├── extrans_vg.py │ │ ├── intrans_vg.py │ │ ├── visual_genome.py │ │ ├── voc.py │ │ └── wsup_visual_genome.py │ ├── samplers │ │ ├── __init__.py │ │ ├── distributed.py │ │ ├── grouped_batch_sampler.py │ │ └── iteration_based_batch_sampler.py │ └── transforms │ │ ├── __init__.py │ │ ├── build.py │ │ └── transforms.py ├── engine │ ├── __init__.py │ ├── bbox_aug.py │ ├── inference.py │ └── trainer.py ├── layers │ ├── __init__.py │ ├── _utils.py │ ├── batch_norm.py │ ├── dcn │ │ ├── __init__.py │ │ ├── deform_conv_func.py │ │ ├── deform_conv_module.py │ │ ├── deform_pool_func.py │ │ └── deform_pool_module.py │ ├── entropy_loss.py │ ├── kl_div_loss.py │ ├── label_smoothing_loss.py │ ├── misc.py │ ├── nms.py │ ├── roi_align.py │ ├── roi_pool.py │ ├── sigmoid_focal_loss.py │ └── smooth_l1_loss.py ├── modeling │ ├── __init__.py │ ├── backbone │ │ ├── __init__.py │ │ ├── backbone.py │ │ ├── fbnet.py │ │ ├── fbnet_builder.py │ │ ├── fbnet_modeldef.py │ │ ├── fpn.py │ │ ├── resnet.py │ │ └── vgg.py │ ├── balanced_positive_negative_sampler.py │ ├── box_coder.py │ ├── detector │ │ ├── __init__.py │ │ ├── detectors.py │ │ └── generalized_rcnn.py │ ├── make_layers.py │ ├── matcher.py │ ├── poolers.py │ ├── registry.py │ ├── roi_heads │ │ ├── __init__.py │ │ ├── attribute_head │ │ │ ├── __init__.py │ │ │ ├── attribute_head.py │ │ │ ├── loss.py │ │ │ ├── roi_attribute_feature_extractors.py │ │ │ └── roi_attribute_predictors.py │ │ ├── box_head │ │ │ ├── __init__.py │ │ │ ├── box_head.py │ │ │ ├── inference.py │ │ │ ├── loss.py │ │ │ ├── roi_box_feature_extractors.py │ │ │ ├── roi_box_predictors.py │ │ │ └── sampling.py │ │ ├── keypoint_head │ │ │ ├── __init__.py │ │ │ ├── inference.py │ │ │ ├── keypoint_head.py │ │ │ ├── loss.py │ │ │ ├── roi_keypoint_feature_extractors.py │ │ │ └── roi_keypoint_predictors.py │ │ ├── mask_head │ │ │ ├── __init__.py │ │ │ ├── inference.py │ │ │ ├── loss.py │ │ │ ├── mask_head.py │ │ │ ├── roi_mask_feature_extractors.py │ │ │ └── roi_mask_predictors.py │ │ ├── relation_head │ │ │ ├── __init__.py │ │ │ ├── classifier.py │ │ │ ├── inference.py │ │ │ ├── loss.py │ │ │ ├── model_bgnn.py │ │ │ ├── model_bgnn_gsl.py │ │ │ ├── model_gpsnet.py │ │ │ ├── model_hetsgg_plus.py │ │ │ ├── model_kern.py │ │ │ ├── model_motifs.py │ │ │ ├── model_motifs_with_attribute.py │ │ │ ├── model_msg_passing.py │ │ │ ├── model_msg_passing_gps.py │ │ │ ├── model_st_sgg.py │ │ │ ├── model_transformer.py │ │ │ ├── model_union.py │ │ │ ├── model_vctree.py │ │ │ ├── model_vtranse.py │ │ │ ├── rel_proposal_network │ │ │ │ ├── __init__.py │ │ │ │ ├── loss.py │ │ │ │ └── models.py │ │ │ ├── relation_head.py │ │ │ ├── roi_relation_feature_extractors.py │ │ │ ├── roi_relation_predictors.py │ │ │ ├── sampling.py │ │ │ ├── utils_motifs.py │ │ │ ├── utils_relation.py │ │ │ ├── utils_treelstm.py │ │ │ └── utils_vctree.py │ │ └── roi_heads.py │ ├── rpn │ │ ├── __init__.py │ │ ├── anchor_generator.py │ │ ├── inference.py │ │ ├── loss.py │ │ ├── retinanet │ │ │ ├── __init__.py │ │ │ ├── inference.py │ │ │ ├── loss.py │ │ │ └── retinanet.py │ │ ├── rpn.py │ │ └── utils.py │ └── utils.py ├── solver │ ├── __init__.py │ ├── build.py │ └── lr_scheduler.py ├── structures │ ├── __init__.py │ ├── bounding_box.py │ ├── boxlist_ops.py │ ├── image_list.py │ ├── keypoint.py │ └── segmentation_mask.py └── utils │ ├── README.md │ ├── __init__.py │ ├── c2_model_loading.py │ ├── checkpoint.py │ ├── collect_env.py │ ├── comm.py │ ├── cv2_util.py │ ├── env.py │ ├── global_buffer.py │ ├── imports.py │ ├── logger.py │ ├── metric_logger.py │ ├── miscellaneous.py │ ├── model_serialization.py │ ├── model_zoo.py │ ├── registry.py │ └── timer.py ├── run_shell ├── bgnn │ ├── predcls │ │ ├── bilvl │ │ │ ├── pretrain.sh │ │ │ └── train_stsgg.sh │ │ └── ie_trans │ │ │ ├── relabel │ │ │ ├── combine.sh │ │ │ ├── external.sh │ │ │ ├── internal.sh │ │ │ └── pretrain.sh │ │ │ ├── train.sh │ │ │ └── train_stsgg.sh │ ├── sgcls │ │ ├── bilvl │ │ │ ├── pretrain.sh │ │ │ └── train_stsgg.sh │ │ └── ie_trans │ │ │ ├── train.sh │ │ │ └── train_stsgg.sh │ └── sgdet │ │ ├── bilvl │ │ ├── pretrain.sh │ │ └── train_stsgg.sh │ │ └── ie_trans │ │ ├── train.sh │ │ └── train_stsgg.sh ├── evaluation.sh ├── evaluation4pretrained_model.sh ├── hetsgg │ ├── predcls │ │ ├── bilvl │ │ │ ├── pretrain.sh │ │ │ └── train_stsgg.sh │ │ └── ie_trans │ │ │ ├── relabel │ │ │ ├── combine.sh │ │ │ ├── external.sh │ │ │ ├── internal.sh │ │ │ └── pretrain.sh │ │ │ ├── train.sh │ │ │ └── train_stsgg.sh │ ├── sgcls │ │ ├── bilvl │ │ │ ├── pretrain.sh │ │ │ └── train_stsgg.sh │ │ └── ie_trans │ │ │ ├── train.sh │ │ │ └── train_stsgg.sh │ └── sgdet │ │ ├── bilvl │ │ ├── pretrain.sh │ │ └── train_stsgg.sh │ │ └── ie_trans │ │ ├── train.sh │ │ └── train_stsgg.sh └── motif │ ├── predcls │ ├── bilvl │ │ ├── pretrain.sh │ │ └── train_stsgg.sh │ ├── ie_trans │ │ ├── relabel │ │ │ ├── combine.sh │ │ │ ├── external.sh │ │ │ ├── internal.sh │ │ │ └── pretrain.sh │ │ ├── train.sh │ │ └── train_stsgg.sh │ └── vanilla │ │ ├── pretrain.sh │ │ └── train_stsgg.sh │ ├── sgcls │ ├── bilvl │ │ ├── pretrain.sh │ │ └── train_stsgg.sh │ ├── ie_trans │ │ ├── train.sh │ │ └── train_stsgg.sh │ └── vanilla │ │ ├── pretrain.sh │ │ └── train_stsgg.sh │ └── sgdet │ ├── bilvl │ ├── pretrain.sh │ └── train_stsgg.sh │ ├── ie_trans │ ├── train.sh │ └── train_stsgg.sh │ └── vanilla │ ├── pretrain.sh │ └── train_stsgg.sh ├── setup.py └── tools ├── demo.py ├── external_relabel.py ├── ietrans ├── combine.py ├── external_cut.py ├── internal_cut.py └── na_score_rank.py ├── internal_relabel.py ├── relation_test_net.py ├── relation_train_net.py └── vg1800 └── combine.py /Prototype-based Graph Information Bottleneck/README.md: -------------------------------------------------------------------------------- 1 | # Interpretable Prototype-based Graph Information Bottleneck 2 | Official Repository of "Interpretable Prototype-based Graph Information Bottleneck" accepted at NeurIPS 2023. 3 | 4 | **Sangwoo Seo, Sungwon Kim, Chanyoung Park** 5 | 6 | # Overview of Prototype-based Graph Information Bottleneck. 7 | ![architecture2_page-0001](./image_architecture.jpg) 8 | 9 | # Paper description and Main Idea: 10 | The success of Graph Neural Networks (GNNs) has led to a need for understanding their decision-making process and providing explanations for their predictions, which has given rise to explainable AI (XAI) that offers transparent explanations for black-box models. Recently, the use of prototypes has successfully improved the explainability of models by learning prototypes to imply training graphs that affect the prediction. However, these approaches tend to provide prototypes with excessive information from the entire graph, leading to the exclusion of key substructures or the inclusion of irrelevant substructures, which can limit both the interpretability and the performance of the model in downstream tasks. In this work, we propose a novel framework of explainable GNNs, called interpretable Prototype-based Graph Information Bottleneck (PGIB) that incorporates prototype learning within the information bottleneck framework to provide prototypes with the key subgraph from the input graph that is important for the model prediction. This is the first work that incorporates prototype learning into the process of identifying the key subgraphs that have a critical impact on the prediction performance. 11 | 12 | # Contribution 13 | * We propose an effective approach, PGIB, that not only improves the interpretability of the reasoning process, but also the overall performance in downstream tasks by incorporating the prototype learning in a process of detecting key subgraphs based on the IB framework. 14 | * We provide theoretical background with our method that utilizes interpretable prototypes in the process of optimizing key subgraphs. 15 | * Extensive experiments, including qualitative analysis, demonstrate that PGIB outperforms state-of-the-art methods in terms of both prediction performance and explainability. 16 | 17 | 18 | # Run (Train & Evaluation) 19 | 20 | ``` 21 | python -m models.train_gnns 22 | ``` 23 | 24 | # Reference 25 | If you find the code useful for your research, please consider citing 26 | ```bib 27 | @misc{seo2023interpretable, 28 | title={Interpretable Prototype-based Graph Information Bottleneck}, 29 | author={Sangwoo Seo and Sungwon Kim and Chanyoung Park}, 30 | year={2023}, 31 | eprint={2310.19906}, 32 | archivePrefix={arXiv}, 33 | primaryClass={cs.LG} 34 | } 35 | ``` 36 | 37 | This work is heavily built upon the code from 38 | * Zhang, Zaixi, et al. "Protgnn: Towards self-explaining graph neural networks." Proceedings of the AAAI Conference on Artificial Intelligence. Vol. 36. No. 8. 2022. 39 | -------------------------------------------------------------------------------- /Prototype-based Graph Information Bottleneck/image_architecture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Prototype-based Graph Information Bottleneck/image_architecture.jpg -------------------------------------------------------------------------------- /Prototype-based Graph Information Bottleneck/models/__init__.py: -------------------------------------------------------------------------------- 1 | import torch.nn as nn 2 | from models.GCN import GCNNet 3 | from models.GAT import GATNet 4 | from models.GIN import GINNet 5 | 6 | __all__ = ['GnnNets'] 7 | 8 | 9 | def get_model(input_dim, output_dim, model_args): 10 | if model_args.model_name.lower() == 'gcn': 11 | return GCNNet(input_dim, output_dim, model_args) 12 | elif model_args.model_name.lower() == 'gat': 13 | return GATNet(input_dim, output_dim, model_args) 14 | elif model_args.model_name.lower() == 'gin': 15 | return GINNet(input_dim, output_dim, model_args) 16 | else: 17 | raise NotImplementedError 18 | 19 | 20 | class GnnBase(nn.Module): 21 | def __init__(self): 22 | super(GnnBase, self).__init__() 23 | 24 | def forward(self, data): 25 | data = data.to(self.device) 26 | logits, prob, emb1, emb2, min_distances = self.model(data) 27 | return logits, prob, emb1, emb2, min_distances 28 | 29 | def update_state_dict(self, state_dict): 30 | original_state_dict = self.state_dict() 31 | loaded_state_dict = dict() 32 | for k, v in state_dict.items(): 33 | if k in original_state_dict.keys(): 34 | loaded_state_dict[k] = v 35 | self.load_state_dict(loaded_state_dict) 36 | 37 | def to_device(self): 38 | self.to(self.device) 39 | 40 | def save_state_dict(self): 41 | pass 42 | 43 | 44 | class GnnNets(GnnBase): 45 | def __init__(self, input_dim, output_dim, model_args): 46 | super(GnnNets, self).__init__() 47 | self.model = get_model(input_dim, output_dim, model_args) 48 | self.device = model_args.device 49 | 50 | def forward(self, data, merge=True): 51 | data = data.to(self.device) 52 | logits, probs, active_node_index, graph_emb, KL_Loss, pos_penalty, sim_matrix, min_distance = self.model(data, merge=True) 53 | return logits, probs, active_node_index, graph_emb, KL_Loss, pos_penalty, sim_matrix, min_distance 54 | 55 | 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Multimodal-Graph-Representation 2 | 3 | #### This repository organizes researches related to AI Technology Development for Commonsense Extraction, Reasoning, and Inference from Heterogeneous Data, especially Multimodal-Graph-Representation task. 4 | #### This repository summarizes following researches. 5 | 6 | ## Research list 7 | * Interpretable Prototype-based Graph Information Bottleneck (NuerIPS 2023) - Sangwoo Seo, Sungwon Kim, and Chanyoung Park. 8 | 9 | * The proposed novel framework of explainable GNNs, called interpretable Prototype-based Graph Information Bottleneck (PGIB) that incorporates prototype learning within the information bottleneck framework to provide prototypes with the key subgraph from the input graph that is important for the model prediction. 10 | 11 | * Adaptive Self-training Framework for Fine-grained Scene Graph Generation (ICLR 2024) - Kibum Kim, Kanghoon Yoon, Yeonjun In, Jinyoung Moon, Donghyun Kim, Chanyoung Park 12 | 13 | * The proposed Self-Training framework for Scene Graph Generation (ST-SGG) utilizes class-specific adaptive thresholding method equipped with EMA approach and class-specific momentum to address the challenges of long-tailed predicates and semantic ambiguity. -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/.gitignore: -------------------------------------------------------------------------------- 1 | # compilation and distribution 2 | __pycache__ 3 | _ext 4 | *.pyc 5 | *.so 6 | maskrcnn_benchmark.egg-info/ 7 | build/ 8 | dist/ 9 | .pytest_cache 10 | 11 | # ipython/jupyter notebooks 12 | #*.ipynb 13 | **/.ipynb_checkpoints/ 14 | 15 | # checkpoint 16 | checkpoint/ 17 | 18 | # dataset 19 | # *.png 20 | *.jpg 21 | *.jpeg 22 | 23 | # Editor temporaries 24 | *.swn 25 | *.swo 26 | *.swp 27 | *~ 28 | *.pth 29 | # Pycharm editor settings 30 | .idea 31 | 32 | # vscode editor settings 33 | .vscode 34 | 35 | # MacOS 36 | .DS_Store 37 | checkpoints/ 38 | predcls-HetSGGPredictor_plus-vg/ 39 | output/ 40 | datasets_vg/ 41 | build/ 42 | tmp/ 43 | initial_data/BGNN_origin/ 44 | initial_data/internal/ 45 | initial_data/predcls/ 46 | My_Shell/ 47 | shell/ 48 | visualization/ 49 | demo/ 50 | cocoapi/ 51 | cmds/ 52 | apex/ 53 | Analysis/ 54 | .vscode/ 55 | configs_save/ 56 | requirements.txt 57 | 1000DS_VG_VGKB_train_statistics.cache 58 | 50DS_VG_VGKB_train_statistics.cache 59 | .vscode/ 60 | obj_pred_info_1800 61 | Pretrained_model/vg_faster_det.pth 62 | pretrained_model 63 | VCTree_predcls 64 | VCTree_sgcls 65 | VCTree_sgdet 66 | VCTreerwt_predcls 67 | VCTreerwt_sgcls 68 | VCTreerwt_sgdet 69 | VCTree 70 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/DATASET.md: -------------------------------------------------------------------------------- 1 | # Dataset: Visual Genome 50 2 | 3 | We follow the same-preprocessing strategy used in [IE-Trans](https://arxiv.org/pdf/2203.11654.pdf). Please download the linked files to prepare the dataset. 4 | 5 | * Download the raw image dataset followed by links [part1 (9 Gb)](https://cs.stanford.edu/people/rak248/VG_100K_2/images.zip), [part2 (5 Gb)](https://cs.stanford.edu/people/rak248/VG_100K_2/images2.zip). After downloading the two files, put the datasets into **datasets/vg/50** directory. 6 | 7 | 8 | 9 | * Download the [image_data.json](https://drive.google.com/file/d/1gfpXlVJkQsVg7-psFlPqU9ZBo3xsuUHF/view?usp=share_link) and [meta-data(VG-50)](https://drive.google.com/file/d/1jWOrsxkRQ5Ov-5jdfG3jOjZMQktySf-k/view?usp=share_link) and put this data into **datasets/vg/50** directory. 10 | 11 | 12 | You should check the dataset path in `maskrcnn_benchmark/config/paths_catalog.py`. Refer to the example of config as: 13 | ``` python 14 | # maskrcnn_benchmark/config/paths_catalog.py => 129 line 15 | "50VG_stanford_filtered_with_attribute": { # check the path associated with dataset 16 | "img_dir": "vg/50/VG_100k", 17 | "roidb_file": "vg/50/VG-SGG-with-attri.h5", 18 | "dict_file": "vg/50/VG-SGG-dicts-with-attri.json", 19 | "image_file": "vg/50/image_data.json", 20 | }, 21 | ``` 22 | 23 | ## I-Trans Dataset 24 | 25 | To reproduce the **I-Trans+ST-SGG** performance, we also provide the dataset adopted the I-Trans for each SGG model. Following the IE-Trans, we apply *k_i* parameter, which decide the amount of changing the annotated dataset, as 0.7. For more details, refer to [IE-Trans](https://github.com/waxnkw/IETrans-SGG.pytorch/blob/master/MODEL_ZOO.md) To run the I-Trans+ST-SGG, download the below pickle file and put them on `datasets/vg/50/{model_name}` directory. 26 | 27 | * [Motif+I-Trans](https://drive.google.com/file/d/1WRaSADSdjujQzzEn4wqwE6_O2ynWnlCm/view?usp=sharing) 28 | * [VCTree+I-Trans](https://drive.google.com/file/d/1oJI-4FiqQL07VUC5a_lWFuwJ_nRMUMu5/view?usp=sharing) 29 | * [BGNN+I-Trans](https://drive.google.com/file/d/1xeQVIc2GjhlMkB6KH-12XT2e1pxZzFrr/view?usp=sharing) 30 | * [HetSGG+I-Trans](https://drive.google.com/file/d/1IEWE6aUwO40T9Oqs8mcbHUQQ-zZlBskt/view?usp=sharing) 31 | 32 | 33 | 34 | 35 | ## Directory Structure for Dataset 36 | 37 | ```python 38 | root 39 | ├── datasets 40 | │ └── vg 41 | │ └── 50 42 | | │── Category_Type_Info.json 43 | │ │── VG-SGG-with-attri.h5 44 | │ │── VG-SGG-dicts-with-attri.json 45 | │ ├── VGKB.json 46 | │ ├── vg_sup_data 47 | │ ├── vg_clip_logits.pk 48 | │ ├── CCKB.json 49 | │ ├── cc_clip_logits 50 | │ └── VG_100k 51 | │ └── *.png 52 | ``` 53 | 54 | * *Category_Type_Info.json* is for HetSGG predictor. -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/Figure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/Figure.png -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/INSTALL.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | You should install the necessary package to run the code. For using the recent pytorch version, we use the pytorch version as 3.9.0 with CUDA 11.3 version. 4 | 5 | ## Versions of main package 6 | - Python == 3.9.0 7 | 8 | - PyTorch == 1.10.1 (CUDA: 11.3) 9 | 10 | - torchvision == 0.11.2 11 | 12 | - numpy == 1.24.3 13 | 14 | - yacs == 0.1.8 15 | 16 | 17 | 18 | ## Guide for installation 19 | 20 | ```bash 21 | 22 | # Note that python version is 3.9.0 23 | conda create --n stsgg python==3.9.0 24 | conda activate stsgg 25 | 26 | conda install -y ipython scipy h5py 27 | 28 | pip install ninja yacs cython matplotlib tqdm opencv-python overrides gpustat gitpython ipdb graphviz tensorboardx termcolor scikit-learn==1.2.2 29 | 30 | # For the recent version, we use the pytorch 1.10.1 version with CUDA 11.3 31 | conda install pytorch==1.10.1 torchvision==0.11.2 cudatoolkit=11.3 -c pytorch -c conda-forge 32 | 33 | pip install torch-spline-conv torch-cluster -f https://data.pyg.org/whl/torch-1.10.1+11.3.html 34 | pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-1.10.1+11.3.html 35 | pip install torch-geometric 36 | 37 | # install pycocotools 38 | git clone https://github.com/cocodataset/cocoapi.git 39 | cd cocoapi/PythonAPI 40 | python setup.py build_ext install 41 | 42 | # install apex 43 | cd ../.. 44 | git clone https://github.com/NVIDIA/apex.git 45 | cd apex 46 | pip install -v --disable-pip-version-check --no-cache-dir ./ 47 | 48 | cd .. 49 | python setup.py build develop 50 | 51 | 52 | ``` -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/initial_data/obj_pred_info/obj_pred_info_50: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/initial_data/obj_pred_info/obj_pred_info_50 -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/config/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .defaults import _C as cfg 3 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/ROIAlign.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #pragma once 3 | 4 | #include "cpu/vision.h" 5 | 6 | #ifdef WITH_CUDA 7 | #include "cuda/vision.h" 8 | #endif 9 | 10 | // Interface for Python 11 | at::Tensor ROIAlign_forward(const at::Tensor& input, 12 | const at::Tensor& rois, 13 | const float spatial_scale, 14 | const int pooled_height, 15 | const int pooled_width, 16 | const int sampling_ratio) { 17 | if (input.type().is_cuda()) { 18 | #ifdef WITH_CUDA 19 | return ROIAlign_forward_cuda(input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio); 20 | #else 21 | AT_ERROR("Not compiled with GPU support"); 22 | #endif 23 | } 24 | return ROIAlign_forward_cpu(input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio); 25 | } 26 | 27 | at::Tensor ROIAlign_backward(const at::Tensor& grad, 28 | const at::Tensor& rois, 29 | const float spatial_scale, 30 | const int pooled_height, 31 | const int pooled_width, 32 | const int batch_size, 33 | const int channels, 34 | const int height, 35 | const int width, 36 | const int sampling_ratio) { 37 | if (grad.type().is_cuda()) { 38 | #ifdef WITH_CUDA 39 | return ROIAlign_backward_cuda(grad, rois, spatial_scale, pooled_height, pooled_width, batch_size, channels, height, width, sampling_ratio); 40 | #else 41 | AT_ERROR("Not compiled with GPU support"); 42 | #endif 43 | } 44 | AT_ERROR("Not implemented on the CPU"); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/ROIPool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #pragma once 3 | 4 | #include "cpu/vision.h" 5 | 6 | #ifdef WITH_CUDA 7 | #include "cuda/vision.h" 8 | #endif 9 | 10 | 11 | std::tuple ROIPool_forward(const at::Tensor& input, 12 | const at::Tensor& rois, 13 | const float spatial_scale, 14 | const int pooled_height, 15 | const int pooled_width) { 16 | if (input.type().is_cuda()) { 17 | #ifdef WITH_CUDA 18 | return ROIPool_forward_cuda(input, rois, spatial_scale, pooled_height, pooled_width); 19 | #else 20 | AT_ERROR("Not compiled with GPU support"); 21 | #endif 22 | } 23 | AT_ERROR("Not implemented on the CPU"); 24 | } 25 | 26 | at::Tensor ROIPool_backward(const at::Tensor& grad, 27 | const at::Tensor& input, 28 | const at::Tensor& rois, 29 | const at::Tensor& argmax, 30 | const float spatial_scale, 31 | const int pooled_height, 32 | const int pooled_width, 33 | const int batch_size, 34 | const int channels, 35 | const int height, 36 | const int width) { 37 | if (grad.type().is_cuda()) { 38 | #ifdef WITH_CUDA 39 | return ROIPool_backward_cuda(grad, input, rois, argmax, spatial_scale, pooled_height, pooled_width, batch_size, channels, height, width); 40 | #else 41 | AT_ERROR("Not compiled with GPU support"); 42 | #endif 43 | } 44 | AT_ERROR("Not implemented on the CPU"); 45 | } 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/SigmoidFocalLoss.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "cpu/vision.h" 4 | 5 | #ifdef WITH_CUDA 6 | #include "cuda/vision.h" 7 | #endif 8 | 9 | // Interface for Python 10 | at::Tensor SigmoidFocalLoss_forward( 11 | const at::Tensor& logits, 12 | const at::Tensor& targets, 13 | const int num_classes, 14 | const float gamma, 15 | const float alpha) { 16 | if (logits.type().is_cuda()) { 17 | #ifdef WITH_CUDA 18 | return SigmoidFocalLoss_forward_cuda(logits, targets, num_classes, gamma, alpha); 19 | #else 20 | AT_ERROR("Not compiled with GPU support"); 21 | #endif 22 | } 23 | AT_ERROR("Not implemented on the CPU"); 24 | } 25 | 26 | at::Tensor SigmoidFocalLoss_backward( 27 | const at::Tensor& logits, 28 | const at::Tensor& targets, 29 | const at::Tensor& d_losses, 30 | const int num_classes, 31 | const float gamma, 32 | const float alpha) { 33 | if (logits.type().is_cuda()) { 34 | #ifdef WITH_CUDA 35 | return SigmoidFocalLoss_backward_cuda(logits, targets, d_losses, num_classes, gamma, alpha); 36 | #else 37 | AT_ERROR("Not compiled with GPU support"); 38 | #endif 39 | } 40 | AT_ERROR("Not implemented on the CPU"); 41 | } 42 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/cpu/nms_cpu.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #include "cpu/vision.h" 3 | 4 | 5 | template 6 | at::Tensor nms_cpu_kernel(const at::Tensor& dets, 7 | const at::Tensor& scores, 8 | const float threshold) { 9 | AT_ASSERTM(!dets.type().is_cuda(), "dets must be a CPU tensor"); 10 | AT_ASSERTM(!scores.type().is_cuda(), "scores must be a CPU tensor"); 11 | AT_ASSERTM(dets.type() == scores.type(), "dets should have the same type as scores"); 12 | 13 | if (dets.numel() == 0) { 14 | return at::empty({0}, dets.options().dtype(at::kLong).device(at::kCPU)); 15 | } 16 | 17 | auto x1_t = dets.select(1, 0).contiguous(); 18 | auto y1_t = dets.select(1, 1).contiguous(); 19 | auto x2_t = dets.select(1, 2).contiguous(); 20 | auto y2_t = dets.select(1, 3).contiguous(); 21 | 22 | at::Tensor areas_t = (x2_t - x1_t + 1) * (y2_t - y1_t + 1); 23 | 24 | auto order_t = std::get<1>(scores.sort(0, /* descending=*/true)); 25 | 26 | auto ndets = dets.size(0); 27 | at::Tensor suppressed_t = at::zeros({ndets}, dets.options().dtype(at::kByte).device(at::kCPU)); 28 | 29 | auto suppressed = suppressed_t.data(); 30 | auto order = order_t.data(); 31 | auto x1 = x1_t.data(); 32 | auto y1 = y1_t.data(); 33 | auto x2 = x2_t.data(); 34 | auto y2 = y2_t.data(); 35 | auto areas = areas_t.data(); 36 | 37 | for (int64_t _i = 0; _i < ndets; _i++) { 38 | auto i = order[_i]; 39 | if (suppressed[i] == 1) 40 | continue; 41 | auto ix1 = x1[i]; 42 | auto iy1 = y1[i]; 43 | auto ix2 = x2[i]; 44 | auto iy2 = y2[i]; 45 | auto iarea = areas[i]; 46 | 47 | for (int64_t _j = _i + 1; _j < ndets; _j++) { 48 | auto j = order[_j]; 49 | if (suppressed[j] == 1) 50 | continue; 51 | auto xx1 = std::max(ix1, x1[j]); 52 | auto yy1 = std::max(iy1, y1[j]); 53 | auto xx2 = std::min(ix2, x2[j]); 54 | auto yy2 = std::min(iy2, y2[j]); 55 | 56 | auto w = std::max(static_cast(0), xx2 - xx1 + 1); 57 | auto h = std::max(static_cast(0), yy2 - yy1 + 1); 58 | auto inter = w * h; 59 | auto ovr = inter / (iarea + areas[j] - inter); 60 | if (ovr >= threshold) 61 | suppressed[j] = 1; 62 | } 63 | } 64 | return at::nonzero(suppressed_t == 0).squeeze(1); 65 | } 66 | 67 | at::Tensor nms_cpu(const at::Tensor& dets, 68 | const at::Tensor& scores, 69 | const float threshold) { 70 | at::Tensor result; 71 | AT_DISPATCH_FLOATING_TYPES(dets.type(), "nms", [&] { 72 | result = nms_cpu_kernel(dets, scores, threshold); 73 | }); 74 | return result; 75 | } 76 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/cpu/vision.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #pragma once 3 | #include 4 | 5 | 6 | at::Tensor ROIAlign_forward_cpu(const at::Tensor& input, 7 | const at::Tensor& rois, 8 | const float spatial_scale, 9 | const int pooled_height, 10 | const int pooled_width, 11 | const int sampling_ratio); 12 | 13 | 14 | at::Tensor nms_cpu(const at::Tensor& dets, 15 | const at::Tensor& scores, 16 | const float threshold); 17 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/deform_pool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #pragma once 3 | #include "cpu/vision.h" 4 | 5 | #ifdef WITH_CUDA 6 | #include "cuda/vision.h" 7 | #endif 8 | 9 | 10 | // Interface for Python 11 | void deform_psroi_pooling_forward( 12 | at::Tensor input, 13 | at::Tensor bbox, 14 | at::Tensor trans, 15 | at::Tensor out, 16 | at::Tensor top_count, 17 | const int no_trans, 18 | const float spatial_scale, 19 | const int output_dim, 20 | const int group_size, 21 | const int pooled_size, 22 | const int part_size, 23 | const int sample_per_part, 24 | const float trans_std) 25 | { 26 | if (input.type().is_cuda()) { 27 | #ifdef WITH_CUDA 28 | return deform_psroi_pooling_cuda_forward( 29 | input, bbox, trans, out, top_count, 30 | no_trans, spatial_scale, output_dim, group_size, 31 | pooled_size, part_size, sample_per_part, trans_std 32 | ); 33 | #else 34 | AT_ERROR("Not compiled with GPU support"); 35 | #endif 36 | } 37 | AT_ERROR("Not implemented on the CPU"); 38 | } 39 | 40 | 41 | void deform_psroi_pooling_backward( 42 | at::Tensor out_grad, 43 | at::Tensor input, 44 | at::Tensor bbox, 45 | at::Tensor trans, 46 | at::Tensor top_count, 47 | at::Tensor input_grad, 48 | at::Tensor trans_grad, 49 | const int no_trans, 50 | const float spatial_scale, 51 | const int output_dim, 52 | const int group_size, 53 | const int pooled_size, 54 | const int part_size, 55 | const int sample_per_part, 56 | const float trans_std) 57 | { 58 | if (input.type().is_cuda()) { 59 | #ifdef WITH_CUDA 60 | return deform_psroi_pooling_cuda_backward( 61 | out_grad, input, bbox, trans, top_count, input_grad, trans_grad, 62 | no_trans, spatial_scale, output_dim, group_size, pooled_size, 63 | part_size, sample_per_part, trans_std 64 | ); 65 | #else 66 | AT_ERROR("Not compiled with GPU support"); 67 | #endif 68 | } 69 | AT_ERROR("Not implemented on the CPU"); 70 | } 71 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/nms.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #pragma once 3 | #include "cpu/vision.h" 4 | 5 | #ifdef WITH_CUDA 6 | #include "cuda/vision.h" 7 | #endif 8 | 9 | 10 | at::Tensor nms(const at::Tensor& dets, 11 | const at::Tensor& scores, 12 | const float threshold) { 13 | 14 | if (dets.type().is_cuda()) { 15 | #ifdef WITH_CUDA 16 | // TODO raise error if not compiled with CUDA 17 | if (dets.numel() == 0) 18 | return at::empty({0}, dets.options().dtype(at::kLong).device(at::kCPU)); 19 | auto b = at::cat({dets, scores.unsqueeze(1)}, 1); 20 | return nms_cuda(b, threshold); 21 | #else 22 | AT_ERROR("Not compiled with GPU support"); 23 | #endif 24 | } 25 | 26 | at::Tensor result = nms_cpu(dets, scores, threshold); 27 | return result; 28 | } 29 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/csrc/vision.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #include "nms.h" 3 | #include "ROIAlign.h" 4 | #include "ROIPool.h" 5 | #include "SigmoidFocalLoss.h" 6 | #include "deform_conv.h" 7 | #include "deform_pool.h" 8 | 9 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 10 | m.def("nms", &nms, "non-maximum suppression"); 11 | m.def("roi_align_forward", &ROIAlign_forward, "ROIAlign_forward"); 12 | m.def("roi_align_backward", &ROIAlign_backward, "ROIAlign_backward"); 13 | m.def("roi_pool_forward", &ROIPool_forward, "ROIPool_forward"); 14 | m.def("roi_pool_backward", &ROIPool_backward, "ROIPool_backward"); 15 | m.def("sigmoid_focalloss_forward", &SigmoidFocalLoss_forward, "SigmoidFocalLoss_forward"); 16 | m.def("sigmoid_focalloss_backward", &SigmoidFocalLoss_backward, "SigmoidFocalLoss_backward"); 17 | // dcn-v2 18 | m.def("deform_conv_forward", &deform_conv_forward, "deform_conv_forward"); 19 | m.def("deform_conv_backward_input", &deform_conv_backward_input, "deform_conv_backward_input"); 20 | m.def("deform_conv_backward_parameters", &deform_conv_backward_parameters, "deform_conv_backward_parameters"); 21 | m.def("modulated_deform_conv_forward", &modulated_deform_conv_forward, "modulated_deform_conv_forward"); 22 | m.def("modulated_deform_conv_backward", &modulated_deform_conv_backward, "modulated_deform_conv_backward"); 23 | m.def("deform_psroi_pooling_forward", &deform_psroi_pooling_forward, "deform_psroi_pooling_forward"); 24 | m.def("deform_psroi_pooling_backward", &deform_psroi_pooling_backward, "deform_psroi_pooling_backward"); 25 | } -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .build import make_data_loader, get_dataset_statistics 3 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/collate_batch.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from maskrcnn_benchmark.structures.image_list import to_image_list 3 | 4 | 5 | class BatchCollator(object): 6 | """ 7 | From a list of samples from the dataset, 8 | returns the batched images and targets. 9 | This should be passed to the DataLoader 10 | """ 11 | 12 | def __init__(self, size_divisible=0): 13 | self.size_divisible = size_divisible 14 | 15 | def __call__(self, batch): 16 | transposed_batch = list(zip(*batch)) 17 | images = to_image_list(transposed_batch[0], self.size_divisible) 18 | targets = transposed_batch[1] 19 | img_ids = transposed_batch[2] 20 | return images, targets, img_ids 21 | 22 | 23 | class BBoxAugCollator(object): 24 | """ 25 | From a list of samples from the dataset, 26 | returns the images and targets. 27 | Images should be converted to batched images in `im_detect_bbox_aug` 28 | """ 29 | 30 | def __call__(self, batch): 31 | return list(zip(*batch)) 32 | 33 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .coco import COCODataset 3 | from .concat_dataset import ConcatDataset 4 | from .visual_genome import VGDataset 5 | from .voc import PascalVOCDataset 6 | from .wsup_visual_genome import WVGDataset 7 | from .intrans_vg import InTransDataset 8 | from .extrans_vg import ExTransDataset 9 | 10 | __all__ = ["COCODataset", "ConcatDataset", "PascalVOCDataset", "VGDataset", "WVGDataset", "ExTransDataset", "InTransDataset",] 11 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/concat_dataset.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import bisect 3 | 4 | from torch.utils.data.dataset import ConcatDataset as _ConcatDataset 5 | 6 | 7 | class ConcatDataset(_ConcatDataset): 8 | """ 9 | Same as torch.utils.data.dataset.ConcatDataset, but exposes an extra 10 | method for querying the sizes of the image 11 | """ 12 | 13 | def get_idxs(self, idx): 14 | dataset_idx = bisect.bisect_right(self.cumulative_sizes, idx) 15 | if dataset_idx == 0: 16 | sample_idx = idx 17 | else: 18 | sample_idx = idx - self.cumulative_sizes[dataset_idx - 1] 19 | return dataset_idx, sample_idx 20 | 21 | def get_img_info(self, idx): 22 | dataset_idx, sample_idx = self.get_idxs(idx) 23 | return self.datasets[dataset_idx].get_img_info(sample_idx) 24 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | from maskrcnn_benchmark.data import datasets 2 | 3 | from .coco import coco_evaluation 4 | from .voc import voc_evaluation 5 | from .vg import vg_evaluation 6 | 7 | 8 | def evaluate(cfg, dataset, predictions, output_folder, logger, **kwargs): 9 | """evaluate dataset using different methods based on dataset type. 10 | Args: 11 | dataset: Dataset object 12 | predictions(list[BoxList]): each item in the list represents the 13 | prediction results for one image. 14 | output_folder: output folder, to save evaluation files or results. 15 | **kwargs: other args. 16 | Returns: 17 | evaluation result 18 | """ 19 | args = dict( 20 | cfg=cfg, dataset=dataset, predictions=predictions, output_folder=output_folder, logger=logger, **kwargs 21 | ) 22 | if isinstance(dataset, datasets.COCODataset): 23 | return coco_evaluation(**args) 24 | elif isinstance(dataset, datasets.PascalVOCDataset): 25 | return voc_evaluation(**args) 26 | elif isinstance(dataset, datasets.VGDataset) or isinstance(dataset, datasets.VRDDataset): 27 | return vg_evaluation(**args) 28 | else: 29 | dataset_name = dataset.__class__.__name__ 30 | raise NotImplementedError("Unsupported dataset type {}.".format(dataset_name)) 31 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/coco/__init__.py: -------------------------------------------------------------------------------- 1 | from .coco_eval import do_coco_evaluation 2 | 3 | 4 | def coco_evaluation( 5 | cfg, 6 | dataset, 7 | predictions, 8 | output_folder, 9 | logger, 10 | box_only, 11 | iou_types, 12 | expected_results, 13 | expected_results_sigma_tol, 14 | ): 15 | return do_coco_evaluation( 16 | dataset=dataset, 17 | predictions=predictions, 18 | box_only=box_only, 19 | output_folder=output_folder, 20 | logger=logger, 21 | iou_types=iou_types, 22 | expected_results=expected_results, 23 | expected_results_sigma_tol=expected_results_sigma_tol, 24 | ) 25 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/vg/__init__.py: -------------------------------------------------------------------------------- 1 | from .vg_eval import do_vg_evaluation 2 | 3 | 4 | def vg_evaluation( 5 | cfg, 6 | dataset, 7 | predictions, 8 | output_folder, 9 | logger, 10 | iou_types, 11 | **_ 12 | ): 13 | return do_vg_evaluation( 14 | cfg=cfg, 15 | dataset=dataset, 16 | predictions=predictions, 17 | output_folder=output_folder, 18 | logger=logger, 19 | iou_types=iou_types, 20 | ) 21 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/vg/zeroshot_triplet.pytorch20: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/vg/zeroshot_triplet.pytorch20 -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/vg/zeroshot_triplet.pytorch50: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/vg/zeroshot_triplet.pytorch50 -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/datasets/evaluation/voc/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from .voc_eval import do_voc_evaluation 4 | 5 | 6 | def voc_evaluation(cfg, dataset, predictions, output_folder, logger, box_only, **_): 7 | if box_only: 8 | logger.warning("voc evaluation doesn't support box_only, ignored.") 9 | logger.info("performing voc evaluation, ignored iou_types.") 10 | return do_voc_evaluation( 11 | dataset=dataset, 12 | predictions=predictions, 13 | output_folder=output_folder, 14 | logger=logger, 15 | ) 16 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/samplers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .distributed import DistributedSampler 3 | from .grouped_batch_sampler import GroupedBatchSampler 4 | from .iteration_based_batch_sampler import IterationBasedBatchSampler 5 | 6 | __all__ = ["DistributedSampler", "GroupedBatchSampler", "IterationBasedBatchSampler"] 7 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/samplers/distributed.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | # Code is copy-pasted exactly as in torch.utils.data.distributed. 3 | # FIXME remove this once c10d fixes the bug it has 4 | import math 5 | import torch 6 | import torch.distributed as dist 7 | from torch.utils.data.sampler import Sampler 8 | 9 | 10 | class DistributedSampler(Sampler): 11 | """Sampler that restricts data loading to a subset of the dataset. 12 | It is especially useful in conjunction with 13 | :class:`torch.nn.parallel.DistributedDataParallel`. In such case, each 14 | process can pass a DistributedSampler instance as a DataLoader sampler, 15 | and load a subset of the original dataset that is exclusive to it. 16 | .. note:: 17 | Dataset is assumed to be of constant size. 18 | Arguments: 19 | dataset: Dataset used for sampling. 20 | num_replicas (optional): Number of processes participating in 21 | distributed training. 22 | rank (optional): Rank of the current process within num_replicas. 23 | """ 24 | 25 | def __init__(self, dataset, num_replicas=None, rank=None, shuffle=True): 26 | if num_replicas is None: 27 | if not dist.is_available(): 28 | raise RuntimeError("Requires distributed package to be available") 29 | num_replicas = dist.get_world_size() 30 | if rank is None: 31 | if not dist.is_available(): 32 | raise RuntimeError("Requires distributed package to be available") 33 | rank = dist.get_rank() 34 | self.dataset = dataset 35 | self.num_replicas = num_replicas 36 | self.rank = rank 37 | self.epoch = 0 38 | self.num_samples = int(math.ceil(len(self.dataset) * 1.0 / self.num_replicas)) 39 | self.total_size = self.num_samples * self.num_replicas 40 | self.shuffle = shuffle 41 | 42 | def __iter__(self): 43 | if self.shuffle: 44 | # deterministically shuffle based on epoch 45 | g = torch.Generator() 46 | g.manual_seed(self.epoch) 47 | indices = torch.randperm(len(self.dataset), generator=g).tolist() 48 | else: 49 | indices = torch.arange(len(self.dataset)).tolist() 50 | 51 | # add extra samples to make it evenly divisible 52 | indices += indices[: (self.total_size - len(indices))] 53 | assert len(indices) == self.total_size 54 | 55 | # subsample 56 | offset = self.num_samples * self.rank 57 | indices = indices[offset : offset + self.num_samples] 58 | assert len(indices) == self.num_samples 59 | 60 | return iter(indices) 61 | 62 | def __len__(self): 63 | return self.num_samples 64 | 65 | def set_epoch(self, epoch): 66 | self.epoch = epoch 67 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/samplers/iteration_based_batch_sampler.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from torch.utils.data.sampler import BatchSampler 3 | 4 | 5 | class IterationBasedBatchSampler(BatchSampler): 6 | """ 7 | Wraps a BatchSampler, resampling from it until 8 | a specified number of iterations have been sampled 9 | """ 10 | 11 | def __init__(self, batch_sampler, num_iterations, start_iter=0): 12 | self.batch_sampler = batch_sampler 13 | self.num_iterations = num_iterations 14 | self.start_iter = start_iter 15 | 16 | def __iter__(self): 17 | iteration = self.start_iter 18 | while iteration <= self.num_iterations: 19 | # if the underlying sampler has a set_epoch method, like 20 | # DistributedSampler, used for making each process see 21 | # a different split of the dataset, then set it 22 | if hasattr(self.batch_sampler.sampler, "set_epoch"): 23 | self.batch_sampler.sampler.set_epoch(iteration) 24 | for batch in self.batch_sampler: 25 | iteration += 1 26 | if iteration > self.num_iterations: 27 | break 28 | yield batch 29 | 30 | def __len__(self): 31 | return self.num_iterations 32 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/transforms/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .transforms import Compose 3 | from .transforms import Resize 4 | from .transforms import RandomHorizontalFlip 5 | from .transforms import ToTensor 6 | from .transforms import Normalize 7 | 8 | from .build import build_transforms 9 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/data/transforms/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from . import transforms as T 3 | 4 | 5 | def build_transforms(cfg, is_train=True): 6 | if is_train: 7 | min_size = cfg.INPUT.MIN_SIZE_TRAIN 8 | max_size = cfg.INPUT.MAX_SIZE_TRAIN 9 | flip_horizontal_prob = 0.5 # cfg.INPUT.FLIP_PROB_TRAIN 10 | flip_vertical_prob = cfg.INPUT.VERTICAL_FLIP_PROB_TRAIN 11 | brightness = cfg.INPUT.BRIGHTNESS 12 | contrast = cfg.INPUT.CONTRAST 13 | saturation = cfg.INPUT.SATURATION 14 | hue = cfg.INPUT.HUE 15 | else: 16 | min_size = cfg.INPUT.MIN_SIZE_TEST 17 | max_size = cfg.INPUT.MAX_SIZE_TEST 18 | flip_horizontal_prob = 0.0 19 | flip_vertical_prob = 0.0 20 | brightness = 0.0 21 | contrast = 0.0 22 | saturation = 0.0 23 | hue = 0.0 24 | 25 | to_bgr255 = cfg.INPUT.TO_BGR255 26 | normalize_transform = T.Normalize( 27 | mean=cfg.INPUT.PIXEL_MEAN, std=cfg.INPUT.PIXEL_STD, to_bgr255=to_bgr255 28 | ) 29 | color_jitter = T.ColorJitter( 30 | brightness=brightness, 31 | contrast=contrast, 32 | saturation=saturation, 33 | hue=hue, 34 | ) 35 | 36 | transform = T.Compose( 37 | [ 38 | color_jitter, 39 | T.Resize(min_size, max_size), 40 | # T.RandomHorizontalFlip(flip_horizontal_prob), 41 | # T.RandomVerticalFlip(flip_vertical_prob), 42 | T.ToTensor(), 43 | normalize_transform, 44 | ] 45 | ) 46 | if cfg.EM.MODE == "E": 47 | transform = T.Compose( 48 | [ 49 | T.Resize(min_size, max_size), 50 | T.ToTensor(), 51 | normalize_transform, 52 | ] 53 | ) 54 | return transform 55 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/engine/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/engine/trainer.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import datetime 3 | import logging 4 | import time 5 | 6 | import torch 7 | import torch.distributed as dist 8 | 9 | from maskrcnn_benchmark.utils.comm import get_world_size 10 | from maskrcnn_benchmark.utils.metric_logger import MetricLogger 11 | 12 | from apex import amp 13 | 14 | def reduce_loss_dict(loss_dict): 15 | """ 16 | Reduce the loss dictionary from all processes so that process with rank 17 | 0 has the averaged results. Returns a dict with the same fields as 18 | loss_dict, after reduction. 19 | """ 20 | world_size = get_world_size() 21 | if world_size < 2: 22 | return loss_dict 23 | with torch.no_grad(): 24 | loss_names = [] 25 | all_losses = [] 26 | for k in sorted(loss_dict.keys()): 27 | loss_names.append(k) 28 | all_losses.append(loss_dict[k]) 29 | all_losses = torch.stack(all_losses, dim=0) 30 | dist.reduce(all_losses, dst=0) 31 | if dist.get_rank() == 0: 32 | # only main process gets accumulated, so only divide by 33 | # world_size in this case 34 | all_losses /= world_size 35 | reduced_losses = {k: v for k, v in zip(loss_names, all_losses)} 36 | return reduced_losses 37 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | 4 | from .batch_norm import FrozenBatchNorm2d 5 | from .misc import Conv2d 6 | from .misc import DFConv2d 7 | from .misc import ConvTranspose2d 8 | from .misc import BatchNorm2d 9 | from .misc import interpolate 10 | from .nms import nms 11 | from .roi_align import ROIAlign 12 | from .roi_align import roi_align 13 | from .roi_pool import ROIPool 14 | from .roi_pool import roi_pool 15 | from .entropy_loss import entropy_loss 16 | from .kl_div_loss import kl_div_loss 17 | from .smooth_l1_loss import smooth_l1_loss 18 | from .sigmoid_focal_loss import SigmoidFocalLoss 19 | from .label_smoothing_loss import Label_Smoothing_Regression 20 | from .dcn.deform_conv_func import deform_conv, modulated_deform_conv 21 | from .dcn.deform_conv_module import DeformConv, ModulatedDeformConv, ModulatedDeformConvPack 22 | from .dcn.deform_pool_func import deform_roi_pooling 23 | from .dcn.deform_pool_module import DeformRoIPooling, DeformRoIPoolingPack, ModulatedDeformRoIPoolingPack 24 | 25 | 26 | __all__ = [ 27 | "nms", 28 | "roi_align", 29 | "ROIAlign", 30 | "roi_pool", 31 | "ROIPool", 32 | "smooth_l1_loss", 33 | "entropy_loss", 34 | "kl_div_loss", 35 | "Conv2d", 36 | "DFConv2d", 37 | "ConvTranspose2d", 38 | "interpolate", 39 | "BatchNorm2d", 40 | "FrozenBatchNorm2d", 41 | "SigmoidFocalLoss", 42 | "Label_Smoothing_Regression", 43 | 'deform_conv', 44 | 'modulated_deform_conv', 45 | 'DeformConv', 46 | 'ModulatedDeformConv', 47 | 'ModulatedDeformConvPack', 48 | 'deform_roi_pooling', 49 | 'DeformRoIPooling', 50 | 'DeformRoIPoolingPack', 51 | 'ModulatedDeformRoIPoolingPack', 52 | ] 53 | 54 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import glob 3 | import os.path 4 | 5 | import torch 6 | 7 | try: 8 | from torch.utils.cpp_extension import load as load_ext 9 | from torch.utils.cpp_extension import CUDA_HOME 10 | except ImportError: 11 | raise ImportError("The cpp layer extensions requires PyTorch 0.4 or higher") 12 | 13 | 14 | def _load_C_extensions(): 15 | this_dir = os.path.dirname(os.path.abspath(__file__)) 16 | this_dir = os.path.dirname(this_dir) 17 | this_dir = os.path.join(this_dir, "csrc") 18 | 19 | main_file = glob.glob(os.path.join(this_dir, "*.cpp")) 20 | source_cpu = glob.glob(os.path.join(this_dir, "cpu", "*.cpp")) 21 | source_cuda = glob.glob(os.path.join(this_dir, "cuda", "*.cu")) 22 | 23 | source = main_file + source_cpu 24 | 25 | extra_cflags = [] 26 | if torch.cuda.is_available() and CUDA_HOME is not None: 27 | source.extend(source_cuda) 28 | extra_cflags = ["-DWITH_CUDA"] 29 | source = [os.path.join(this_dir, s) for s in source] 30 | extra_include_paths = [this_dir] 31 | return load_ext( 32 | "torchvision", 33 | source, 34 | extra_cflags=extra_cflags, 35 | extra_include_paths=extra_include_paths, 36 | ) 37 | 38 | 39 | _C = _load_C_extensions() 40 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/batch_norm.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | from torch import nn 4 | 5 | 6 | class FrozenBatchNorm2d(nn.Module): 7 | """ 8 | BatchNorm2d where the batch statistics and the affine parameters 9 | are fixed 10 | """ 11 | 12 | def __init__(self, n): 13 | super(FrozenBatchNorm2d, self).__init__() 14 | self.register_buffer("weight", torch.ones(n)) 15 | self.register_buffer("bias", torch.zeros(n)) 16 | self.register_buffer("running_mean", torch.zeros(n)) 17 | self.register_buffer("running_var", torch.ones(n)) 18 | 19 | def forward(self, x): 20 | # Cast all fixed parameters to half() if necessary 21 | if x.dtype == torch.float16: 22 | self.weight = self.weight.half() 23 | self.bias = self.bias.half() 24 | self.running_mean = self.running_mean.half() 25 | self.running_var = self.running_var.half() 26 | 27 | scale = self.weight * self.running_var.rsqrt() 28 | bias = self.bias - self.running_mean * scale 29 | scale = scale.reshape(1, -1, 1, 1) 30 | bias = bias.reshape(1, -1, 1, 1) 31 | return x * scale + bias 32 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/dcn/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copied From [mmdetection](https://github.com/open-mmlab/mmdetection/tree/master/mmdet/ops/dcn) 3 | # 4 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/entropy_loss.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | 4 | 5 | def entropy_loss(input, e=1e-9, reduction='sum'): 6 | assert len(input.shape) == 2 7 | loss = - (input * (input + e).log()) 8 | 9 | if reduction == 'sum': 10 | loss = loss.sum(-1) 11 | elif reduction == 'mean': 12 | loss = loss.mean(-1) 13 | 14 | return loss.mean() -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/kl_div_loss.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | 4 | 5 | def kl_div_loss(input, target, e=1e-9, reduction='sum'): 6 | assert len(input.shape) == 2 7 | assert len(target.shape) == 2 8 | 9 | log_target = (target + e).log() 10 | log_input = (input + e).log() 11 | 12 | loss = target.detach() * (log_target.detach() - log_input) 13 | 14 | if reduction == 'sum': 15 | loss = loss.sum(-1) 16 | elif reduction == 'mean': 17 | loss = loss.mean(-1) 18 | 19 | return loss.mean() -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/nms.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | # from ._utils import _C 3 | from maskrcnn_benchmark import _C 4 | 5 | from apex import amp 6 | 7 | # Only valid with fp32 inputs - give AMP the hint 8 | nms = amp.float_function(_C.nms) 9 | 10 | # nms.__doc__ = """ 11 | # This function performs Non-maximum suppresion""" 12 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/roi_align.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | from torch import nn 4 | from torch.autograd import Function 5 | from torch.autograd.function import once_differentiable 6 | from torch.nn.modules.utils import _pair 7 | 8 | from maskrcnn_benchmark import _C 9 | 10 | from apex import amp 11 | 12 | class _ROIAlign(Function): 13 | @staticmethod 14 | def forward(ctx, input, roi, output_size, spatial_scale, sampling_ratio): 15 | ctx.save_for_backward(roi) 16 | ctx.output_size = _pair(output_size) 17 | ctx.spatial_scale = spatial_scale 18 | ctx.sampling_ratio = sampling_ratio 19 | ctx.input_shape = input.size() 20 | output = _C.roi_align_forward( 21 | input, roi, spatial_scale, output_size[0], output_size[1], sampling_ratio 22 | ) 23 | return output 24 | 25 | @staticmethod 26 | @once_differentiable 27 | def backward(ctx, grad_output): 28 | rois, = ctx.saved_tensors 29 | output_size = ctx.output_size 30 | spatial_scale = ctx.spatial_scale 31 | sampling_ratio = ctx.sampling_ratio 32 | bs, ch, h, w = ctx.input_shape 33 | grad_input = _C.roi_align_backward( 34 | grad_output, 35 | rois, 36 | spatial_scale, 37 | output_size[0], 38 | output_size[1], 39 | bs, 40 | ch, 41 | h, 42 | w, 43 | sampling_ratio, 44 | ) 45 | return grad_input, None, None, None, None 46 | 47 | 48 | roi_align = _ROIAlign.apply 49 | 50 | class ROIAlign(nn.Module): 51 | def __init__(self, output_size, spatial_scale, sampling_ratio): 52 | super(ROIAlign, self).__init__() 53 | self.output_size = output_size 54 | self.spatial_scale = spatial_scale 55 | self.sampling_ratio = sampling_ratio 56 | 57 | @amp.float_function 58 | def forward(self, input, rois): 59 | return roi_align( 60 | input, rois, self.output_size, self.spatial_scale, self.sampling_ratio 61 | ) 62 | 63 | def __repr__(self): 64 | tmpstr = self.__class__.__name__ + "(" 65 | tmpstr += "output_size=" + str(self.output_size) 66 | tmpstr += ", spatial_scale=" + str(self.spatial_scale) 67 | tmpstr += ", sampling_ratio=" + str(self.sampling_ratio) 68 | tmpstr += ")" 69 | return tmpstr 70 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/roi_pool.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | from torch import nn 4 | from torch.autograd import Function 5 | from torch.autograd.function import once_differentiable 6 | from torch.nn.modules.utils import _pair 7 | 8 | from maskrcnn_benchmark import _C 9 | 10 | from apex import amp 11 | 12 | class _ROIPool(Function): 13 | @staticmethod 14 | def forward(ctx, input, roi, output_size, spatial_scale): 15 | ctx.output_size = _pair(output_size) 16 | ctx.spatial_scale = spatial_scale 17 | ctx.input_shape = input.size() 18 | output, argmax = _C.roi_pool_forward( 19 | input, roi, spatial_scale, output_size[0], output_size[1] 20 | ) 21 | ctx.save_for_backward(input, roi, argmax) 22 | return output 23 | 24 | @staticmethod 25 | @once_differentiable 26 | def backward(ctx, grad_output): 27 | input, rois, argmax = ctx.saved_tensors 28 | output_size = ctx.output_size 29 | spatial_scale = ctx.spatial_scale 30 | bs, ch, h, w = ctx.input_shape 31 | grad_input = _C.roi_pool_backward( 32 | grad_output, 33 | input, 34 | rois, 35 | argmax, 36 | spatial_scale, 37 | output_size[0], 38 | output_size[1], 39 | bs, 40 | ch, 41 | h, 42 | w, 43 | ) 44 | return grad_input, None, None, None 45 | 46 | 47 | roi_pool = _ROIPool.apply 48 | 49 | 50 | class ROIPool(nn.Module): 51 | def __init__(self, output_size, spatial_scale): 52 | super(ROIPool, self).__init__() 53 | self.output_size = output_size 54 | self.spatial_scale = spatial_scale 55 | 56 | @amp.float_function 57 | def forward(self, input, rois): 58 | return roi_pool(input, rois, self.output_size, self.spatial_scale) 59 | 60 | def __repr__(self): 61 | tmpstr = self.__class__.__name__ + "(" 62 | tmpstr += "output_size=" + str(self.output_size) 63 | tmpstr += ", spatial_scale=" + str(self.spatial_scale) 64 | tmpstr += ")" 65 | return tmpstr 66 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/sigmoid_focal_loss.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch import nn 3 | from torch.autograd import Function 4 | from torch.autograd.function import once_differentiable 5 | 6 | from maskrcnn_benchmark import _C 7 | 8 | # TODO: Use JIT to replace CUDA implementation in the future. 9 | class _SigmoidFocalLoss(Function): 10 | @staticmethod 11 | def forward(ctx, logits, targets, gamma, alpha): 12 | ctx.save_for_backward(logits, targets) 13 | num_classes = logits.shape[1] 14 | ctx.num_classes = num_classes 15 | ctx.gamma = gamma 16 | ctx.alpha = alpha 17 | 18 | losses = _C.sigmoid_focalloss_forward( 19 | logits, targets, num_classes, gamma, alpha 20 | ) 21 | return losses 22 | 23 | @staticmethod 24 | @once_differentiable 25 | def backward(ctx, d_loss): 26 | logits, targets = ctx.saved_tensors 27 | num_classes = ctx.num_classes 28 | gamma = ctx.gamma 29 | alpha = ctx.alpha 30 | d_loss = d_loss.contiguous() 31 | d_logits = _C.sigmoid_focalloss_backward( 32 | logits, targets, d_loss, num_classes, gamma, alpha 33 | ) 34 | return d_logits, None, None, None, None 35 | 36 | 37 | sigmoid_focal_loss_cuda = _SigmoidFocalLoss.apply 38 | 39 | 40 | def sigmoid_focal_loss_cpu(logits, targets, gamma, alpha): 41 | num_classes = logits.shape[1] 42 | gamma = gamma[0] 43 | alpha = alpha[0] 44 | dtype = targets.dtype 45 | device = targets.device 46 | class_range = torch.arange(1, num_classes+1, dtype=dtype, device=device).unsqueeze(0) 47 | 48 | t = targets.unsqueeze(1) 49 | p = torch.sigmoid(logits) 50 | term1 = (1 - p) ** gamma * torch.log(p) 51 | term2 = p ** gamma * torch.log(1 - p) 52 | return -(t == class_range).float() * term1 * alpha - ((t != class_range) * (t >= 0)).float() * term2 * (1 - alpha) 53 | 54 | 55 | class SigmoidFocalLoss(nn.Module): 56 | def __init__(self, gamma, alpha): 57 | super(SigmoidFocalLoss, self).__init__() 58 | self.gamma = gamma 59 | self.alpha = alpha 60 | 61 | def forward(self, logits, targets): 62 | device = logits.device 63 | if logits.is_cuda: 64 | loss_func = sigmoid_focal_loss_cuda 65 | else: 66 | loss_func = sigmoid_focal_loss_cpu 67 | 68 | loss = loss_func(logits, targets, self.gamma, self.alpha) 69 | return loss.sum() 70 | 71 | def __repr__(self): 72 | tmpstr = self.__class__.__name__ + "(" 73 | tmpstr += "gamma=" + str(self.gamma) 74 | tmpstr += ", alpha=" + str(self.alpha) 75 | tmpstr += ")" 76 | return tmpstr 77 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/layers/smooth_l1_loss.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | 4 | 5 | # TODO maybe push this to nn? 6 | def smooth_l1_loss(input, target, beta=1. / 9, size_average=True): 7 | """ 8 | very similar to the smooth_l1_loss from pytorch, but with 9 | the extra beta parameter 10 | """ 11 | n = torch.abs(input - target) 12 | cond = n < beta 13 | loss = torch.where(cond, 0.5 * n ** 2 / beta, n - 0.5 * beta) 14 | if size_average: 15 | return loss.mean() 16 | return loss.sum() 17 | 18 | 19 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/backbone/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .backbone import build_backbone 3 | from . import fbnet 4 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/backbone/vgg.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | """ 3 | Variant of the resnet module that takes cfg as an argument. 4 | Example usage. Strings may be specified in the config file. 5 | model = ResNet( 6 | "StemWithFixedBatchNorm", 7 | "BottleneckWithFixedBatchNorm", 8 | "ResNet50StagesTo4", 9 | ) 10 | OR: 11 | model = ResNet( 12 | "StemWithGN", 13 | "BottleneckWithGN", 14 | "ResNet50StagesTo4", 15 | ) 16 | Custom implementations may be written in user code and hooked in via the 17 | `register_*` functions. 18 | """ 19 | from collections import namedtuple 20 | 21 | import torch 22 | import torch.nn.functional as F 23 | from torch import nn 24 | 25 | import torchvision.models as models 26 | from maskrcnn_benchmark.layers import FrozenBatchNorm2d 27 | from maskrcnn_benchmark.layers import Conv2d 28 | from maskrcnn_benchmark.layers import DFConv2d 29 | from maskrcnn_benchmark.modeling.make_layers import group_norm 30 | from maskrcnn_benchmark.utils.registry import Registry 31 | 32 | 33 | class VGG16(nn.Module): 34 | def __init__(self, cfg): 35 | super(VGG16, self).__init__() 36 | vgg = models.vgg16(pretrained=True) 37 | self.conv_body = nn.Sequential(*list(vgg.features._modules.values())[:-1]) 38 | 39 | def forward(self, x): 40 | output = [] 41 | output.append(self.conv_body(x)) 42 | return output 43 | 44 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/detector/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .detectors import build_detection_model 3 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/detector/detectors.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .generalized_rcnn import GeneralizedRCNN 3 | 4 | 5 | _DETECTION_META_ARCHITECTURES = {"GeneralizedRCNN": GeneralizedRCNN} 6 | 7 | 8 | def build_detection_model(cfg): 9 | meta_arch = _DETECTION_META_ARCHITECTURES[cfg.MODEL.META_ARCHITECTURE] 10 | return meta_arch(cfg) 11 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | """ 3 | Implements the Generalized R-CNN framework 4 | """ 5 | 6 | import torch 7 | from torch import nn 8 | 9 | from maskrcnn_benchmark.structures.image_list import to_image_list 10 | 11 | from ..backbone import build_backbone 12 | from ..rpn.rpn import build_rpn 13 | from ..roi_heads.roi_heads import build_roi_heads 14 | 15 | 16 | class GeneralizedRCNN(nn.Module): 17 | """ 18 | Main class for Generalized R-CNN. Currently supports boxes and masks. 19 | It consists of three main parts: 20 | - backbone 21 | - rpn 22 | - heads: takes the features + the proposals from the RPN and computes 23 | detections / masks from it. 24 | """ 25 | 26 | def __init__(self, cfg): 27 | super(GeneralizedRCNN, self).__init__() 28 | self.cfg = cfg.clone() 29 | self.backbone = build_backbone(cfg) 30 | self.rpn = build_rpn(cfg, self.backbone.out_channels) 31 | self.roi_heads = build_roi_heads(cfg, self.backbone.out_channels) 32 | 33 | def forward(self, images, targets=None, logger=None): 34 | """ 35 | Arguments: 36 | images (list[Tensor] or ImageList): images to be processed 37 | targets (list[BoxList]): ground-truth boxes present in the image (optional) 38 | 39 | Returns: 40 | result (list[BoxList] or dict[Tensor]): the output from the model. 41 | During training, it returns a dict[Tensor] which contains the losses. 42 | During testing, it returns list[BoxList] contains additional fields 43 | like `scores`, `labels` and `mask` (for Mask R-CNN models). 44 | 45 | """ 46 | if self.training and targets is None: 47 | raise ValueError("In training mode, targets should be passed") 48 | images = to_image_list(images) 49 | features = self.backbone(images.tensors) 50 | proposals, proposal_losses = self.rpn(images, features, targets) 51 | if self.roi_heads: 52 | x, result, detector_losses = self.roi_heads(features, proposals, targets, logger) 53 | else: 54 | # RPN-only models don't have roi_heads 55 | x = features 56 | result = proposals 57 | detector_losses = {} 58 | 59 | if self.training: 60 | losses = {} 61 | losses.update(detector_losses) 62 | if not self.cfg.MODEL.RELATION_ON: 63 | # During the relationship training stage, the rpn_head should be fixed, and no loss. 64 | losses.update(proposal_losses) 65 | return losses 66 | 67 | return result 68 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/registry.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | 3 | from maskrcnn_benchmark.utils.registry import Registry 4 | 5 | BACKBONES = Registry() 6 | RPN_HEADS = Registry() 7 | ROI_BOX_FEATURE_EXTRACTORS = Registry() 8 | ROI_BOX_PREDICTOR = Registry() 9 | ROI_ATTRIBUTE_FEATURE_EXTRACTORS = Registry() 10 | ROI_ATTRIBUTE_PREDICTOR = Registry() 11 | ROI_KEYPOINT_FEATURE_EXTRACTORS = Registry() 12 | ROI_KEYPOINT_PREDICTOR = Registry() 13 | ROI_MASK_FEATURE_EXTRACTORS = Registry() 14 | ROI_MASK_PREDICTOR = Registry() 15 | ROI_RELATION_FEATURE_EXTRACTORS = Registry() 16 | ROI_RELATION_PREDICTOR = Registry() 17 | RELATION_CONFIDENCE_AWARE_MODULES = Registry() 18 | 19 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/attribute_head/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/attribute_head/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/attribute_head/roi_attribute_predictors.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from maskrcnn_benchmark.modeling import registry 3 | from torch import nn 4 | 5 | 6 | @registry.ROI_ATTRIBUTE_PREDICTOR.register("FastRCNNPredictor") 7 | class FastRCNNPredictor(nn.Module): 8 | def __init__(self, config, in_channels): 9 | super(FastRCNNPredictor, self).__init__() 10 | assert in_channels is not None 11 | num_inputs = in_channels 12 | 13 | num_attributes = cfg.MODEL.ROI_ATTRIBUTE_HEAD.NUM_ATTRIBUTES 14 | self.avgpool = nn.AdaptiveAvgPool2d(1) 15 | self.att_score = nn.Linear(num_inputs, num_attributes) 16 | 17 | nn.init.normal_(self.att_score.weight, mean=0, std=0.01) 18 | nn.init.constant_(self.att_score.bias, 0) 19 | 20 | def forward(self, x): 21 | x = self.avgpool(x) 22 | x = x.view(x.size(0), -1) 23 | att_logit = self.att_score(x) 24 | 25 | return att_logit 26 | 27 | 28 | @registry.ROI_ATTRIBUTE_PREDICTOR.register("FPNPredictor") 29 | class FPNPredictor(nn.Module): 30 | def __init__(self, cfg, in_channels): 31 | super(FPNPredictor, self).__init__() 32 | num_attributes = cfg.MODEL.ROI_ATTRIBUTE_HEAD.NUM_ATTRIBUTES 33 | representation_size = in_channels 34 | 35 | self.att_score = nn.Linear(representation_size, num_attributes) 36 | 37 | nn.init.normal_(self.att_score.weight, std=0.01) 38 | nn.init.constant_(self.att_score.bias, 0) 39 | 40 | def forward(self, x): 41 | if x.ndimension() == 4: 42 | assert list(x.shape[2:]) == [1, 1] 43 | x = x.view(x.size(0), -1) 44 | 45 | att_logit = self.att_score(x) 46 | 47 | return att_logit 48 | 49 | 50 | def make_roi_attribute_predictor(cfg, in_channels): 51 | func = registry.ROI_ATTRIBUTE_PREDICTOR[cfg.MODEL.ROI_ATTRIBUTE_HEAD.PREDICTOR] 52 | return func(cfg, in_channels) 53 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/box_head/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/box_head/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/box_head/roi_box_predictors.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from maskrcnn_benchmark.modeling import registry 3 | from torch import nn 4 | 5 | 6 | @registry.ROI_BOX_PREDICTOR.register("FastRCNNPredictor") 7 | class FastRCNNPredictor(nn.Module): 8 | def __init__(self, config, in_channels): 9 | super(FastRCNNPredictor, self).__init__() 10 | assert in_channels is not None 11 | num_inputs = in_channels 12 | 13 | num_classes = config.MODEL.ROI_BOX_HEAD.NUM_CLASSES 14 | self.avgpool = nn.AdaptiveAvgPool2d(1) 15 | self.cls_score = nn.Linear(num_inputs, num_classes) 16 | num_bbox_reg_classes = 2 if config.MODEL.CLS_AGNOSTIC_BBOX_REG else num_classes 17 | self.bbox_pred = nn.Linear(num_inputs, num_bbox_reg_classes * 4) 18 | 19 | nn.init.normal_(self.cls_score.weight, mean=0, std=0.01) 20 | nn.init.constant_(self.cls_score.bias, 0) 21 | 22 | nn.init.normal_(self.bbox_pred.weight, mean=0, std=0.001) 23 | nn.init.constant_(self.bbox_pred.bias, 0) 24 | 25 | def forward(self, x): 26 | x = self.avgpool(x) 27 | x = x.view(x.size(0), -1) 28 | cls_logit = self.cls_score(x) 29 | bbox_pred = self.bbox_pred(x) 30 | return cls_logit, bbox_pred 31 | 32 | 33 | @registry.ROI_BOX_PREDICTOR.register("FPNPredictor") 34 | class FPNPredictor(nn.Module): 35 | def __init__(self, cfg, in_channels): 36 | super(FPNPredictor, self).__init__() 37 | num_classes = cfg.MODEL.ROI_BOX_HEAD.NUM_CLASSES 38 | representation_size = in_channels 39 | 40 | self.cls_score = nn.Linear(representation_size, num_classes) 41 | num_bbox_reg_classes = 2 if cfg.MODEL.CLS_AGNOSTIC_BBOX_REG else num_classes 42 | self.bbox_pred = nn.Linear(representation_size, num_bbox_reg_classes * 4) 43 | 44 | nn.init.normal_(self.cls_score.weight, std=0.01) 45 | nn.init.normal_(self.bbox_pred.weight, std=0.001) 46 | for l in [self.cls_score, self.bbox_pred]: 47 | nn.init.constant_(l.bias, 0) 48 | 49 | def forward(self, x): 50 | if x.ndimension() == 4: 51 | assert list(x.shape[2:]) == [1, 1] 52 | x = x.view(x.size(0), -1) 53 | cls_logit = self.cls_score(x) 54 | bbox_pred = self.bbox_pred(x) 55 | 56 | return cls_logit, bbox_pred 57 | 58 | 59 | def make_roi_box_predictor(cfg, in_channels): 60 | func = registry.ROI_BOX_PREDICTOR[cfg.MODEL.ROI_BOX_HEAD.PREDICTOR] 61 | return func(cfg, in_channels) 62 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/keypoint_head/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/keypoint_head/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/keypoint_head/keypoint_head.py: -------------------------------------------------------------------------------- 1 | import torch 2 | 3 | from .roi_keypoint_feature_extractors import make_roi_keypoint_feature_extractor 4 | from .roi_keypoint_predictors import make_roi_keypoint_predictor 5 | from .inference import make_roi_keypoint_post_processor 6 | from .loss import make_roi_keypoint_loss_evaluator 7 | 8 | 9 | class ROIKeypointHead(torch.nn.Module): 10 | def __init__(self, cfg, in_channels): 11 | super(ROIKeypointHead, self).__init__() 12 | self.cfg = cfg.clone() 13 | self.feature_extractor = make_roi_keypoint_feature_extractor(cfg, in_channels) 14 | self.predictor = make_roi_keypoint_predictor( 15 | cfg, self.feature_extractor.out_channels) 16 | self.post_processor = make_roi_keypoint_post_processor(cfg) 17 | self.loss_evaluator = make_roi_keypoint_loss_evaluator(cfg) 18 | 19 | def forward(self, features, proposals, targets=None): 20 | """ 21 | Arguments: 22 | features (list[Tensor]): feature-maps from possibly several levels 23 | proposals (list[BoxList]): proposal boxes 24 | targets (list[BoxList], optional): the ground-truth targets. 25 | 26 | Returns: 27 | x (Tensor): the result of the feature extractor 28 | proposals (list[BoxList]): during training, the original proposals 29 | are returned. During testing, the predicted boxlists are returned 30 | with the `mask` field set 31 | losses (dict[Tensor]): During training, returns the losses for the 32 | head. During testing, returns an empty dict. 33 | """ 34 | if self.training: 35 | with torch.no_grad(): 36 | proposals = self.loss_evaluator.subsample(proposals, targets) 37 | 38 | x = self.feature_extractor(features, proposals) 39 | kp_logits = self.predictor(x) 40 | 41 | if not self.training: 42 | result = self.post_processor(kp_logits, proposals) 43 | return x, result, {} 44 | 45 | loss_kp = self.loss_evaluator(proposals, kp_logits) 46 | 47 | return x, proposals, dict(loss_kp=loss_kp) 48 | 49 | 50 | def build_roi_keypoint_head(cfg, in_channels): 51 | return ROIKeypointHead(cfg, in_channels) 52 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/keypoint_head/roi_keypoint_feature_extractors.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | from torch.nn import functional as F 3 | 4 | from maskrcnn_benchmark.modeling import registry 5 | from maskrcnn_benchmark.modeling.poolers import Pooler 6 | 7 | from maskrcnn_benchmark.layers import Conv2d 8 | 9 | 10 | @registry.ROI_KEYPOINT_FEATURE_EXTRACTORS.register("KeypointRCNNFeatureExtractor") 11 | class KeypointRCNNFeatureExtractor(nn.Module): 12 | def __init__(self, cfg, in_channels): 13 | super(KeypointRCNNFeatureExtractor, self).__init__() 14 | 15 | resolution = cfg.MODEL.ROI_KEYPOINT_HEAD.POOLER_RESOLUTION 16 | scales = cfg.MODEL.ROI_KEYPOINT_HEAD.POOLER_SCALES 17 | sampling_ratio = cfg.MODEL.ROI_KEYPOINT_HEAD.POOLER_SAMPLING_RATIO 18 | pooler = Pooler( 19 | output_size=(resolution, resolution), 20 | scales=scales, 21 | sampling_ratio=sampling_ratio, 22 | ) 23 | self.pooler = pooler 24 | 25 | input_features = in_channels 26 | layers = cfg.MODEL.ROI_KEYPOINT_HEAD.CONV_LAYERS 27 | next_feature = input_features 28 | self.blocks = [] 29 | for layer_idx, layer_features in enumerate(layers, 1): 30 | layer_name = "conv_fcn{}".format(layer_idx) 31 | module = Conv2d(next_feature, layer_features, 3, stride=1, padding=1) 32 | nn.init.kaiming_normal_(module.weight, mode="fan_out", nonlinearity="relu") 33 | nn.init.constant_(module.bias, 0) 34 | self.add_module(layer_name, module) 35 | next_feature = layer_features 36 | self.blocks.append(layer_name) 37 | self.out_channels = layer_features 38 | 39 | def forward(self, x, proposals): 40 | x = self.pooler(x, proposals) 41 | for layer_name in self.blocks: 42 | x = F.relu(getattr(self, layer_name)(x)) 43 | return x 44 | 45 | 46 | def make_roi_keypoint_feature_extractor(cfg, in_channels): 47 | func = registry.ROI_KEYPOINT_FEATURE_EXTRACTORS[ 48 | cfg.MODEL.ROI_KEYPOINT_HEAD.FEATURE_EXTRACTOR 49 | ] 50 | return func(cfg, in_channels) 51 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/keypoint_head/roi_keypoint_predictors.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | 3 | from maskrcnn_benchmark import layers 4 | from maskrcnn_benchmark.modeling import registry 5 | 6 | 7 | @registry.ROI_KEYPOINT_PREDICTOR.register("KeypointRCNNPredictor") 8 | class KeypointRCNNPredictor(nn.Module): 9 | def __init__(self, cfg, in_channels): 10 | super(KeypointRCNNPredictor, self).__init__() 11 | input_features = in_channels 12 | num_keypoints = cfg.MODEL.ROI_KEYPOINT_HEAD.NUM_CLASSES 13 | deconv_kernel = 4 14 | self.kps_score_lowres = layers.ConvTranspose2d( 15 | input_features, 16 | num_keypoints, 17 | deconv_kernel, 18 | stride=2, 19 | padding=deconv_kernel // 2 - 1, 20 | ) 21 | nn.init.kaiming_normal_( 22 | self.kps_score_lowres.weight, mode="fan_out", nonlinearity="relu" 23 | ) 24 | nn.init.constant_(self.kps_score_lowres.bias, 0) 25 | self.up_scale = 2 26 | self.out_channels = num_keypoints 27 | 28 | def forward(self, x): 29 | x = self.kps_score_lowres(x) 30 | x = layers.interpolate( 31 | x, scale_factor=self.up_scale, mode="bilinear", align_corners=False 32 | ) 33 | return x 34 | 35 | 36 | def make_roi_keypoint_predictor(cfg, in_channels): 37 | func = registry.ROI_KEYPOINT_PREDICTOR[cfg.MODEL.ROI_KEYPOINT_HEAD.PREDICTOR] 38 | return func(cfg, in_channels) 39 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/mask_head/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/mask_head/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/mask_head/roi_mask_feature_extractors.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from torch import nn 3 | from torch.nn import functional as F 4 | 5 | from ..box_head.roi_box_feature_extractors import ResNet50Conv5ROIFeatureExtractor 6 | from maskrcnn_benchmark.modeling import registry 7 | from maskrcnn_benchmark.modeling.poolers import Pooler 8 | from maskrcnn_benchmark.modeling.make_layers import make_conv3x3 9 | 10 | 11 | registry.ROI_MASK_FEATURE_EXTRACTORS.register( 12 | "ResNet50Conv5ROIFeatureExtractor", ResNet50Conv5ROIFeatureExtractor 13 | ) 14 | 15 | 16 | @registry.ROI_MASK_FEATURE_EXTRACTORS.register("MaskRCNNFPNFeatureExtractor") 17 | class MaskRCNNFPNFeatureExtractor(nn.Module): 18 | """ 19 | Heads for FPN for classification 20 | """ 21 | 22 | def __init__(self, cfg, in_channels): 23 | """ 24 | Arguments: 25 | num_classes (int): number of output classes 26 | input_size (int): number of channels of the input once it's flattened 27 | representation_size (int): size of the intermediate representation 28 | """ 29 | super(MaskRCNNFPNFeatureExtractor, self).__init__() 30 | 31 | resolution = cfg.MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION 32 | scales = cfg.MODEL.ROI_MASK_HEAD.POOLER_SCALES 33 | sampling_ratio = cfg.MODEL.ROI_MASK_HEAD.POOLER_SAMPLING_RATIO 34 | pooler = Pooler( 35 | output_size=(resolution, resolution), 36 | scales=scales, 37 | sampling_ratio=sampling_ratio, 38 | ) 39 | input_size = in_channels 40 | self.pooler = pooler 41 | 42 | use_gn = cfg.MODEL.ROI_MASK_HEAD.USE_GN 43 | layers = cfg.MODEL.ROI_MASK_HEAD.CONV_LAYERS 44 | dilation = cfg.MODEL.ROI_MASK_HEAD.DILATION 45 | 46 | next_feature = input_size 47 | self.blocks = [] 48 | for layer_idx, layer_features in enumerate(layers, 1): 49 | layer_name = "mask_fcn{}".format(layer_idx) 50 | module = make_conv3x3( 51 | next_feature, layer_features, 52 | dilation=dilation, stride=1, use_gn=use_gn 53 | ) 54 | self.add_module(layer_name, module) 55 | next_feature = layer_features 56 | self.blocks.append(layer_name) 57 | self.out_channels = layer_features 58 | 59 | def forward(self, x, proposals): 60 | x = self.pooler(x, proposals) 61 | 62 | for layer_name in self.blocks: 63 | x = F.relu(getattr(self, layer_name)(x)) 64 | 65 | return x 66 | 67 | 68 | def make_roi_mask_feature_extractor(cfg, in_channels): 69 | func = registry.ROI_MASK_FEATURE_EXTRACTORS[ 70 | cfg.MODEL.ROI_MASK_HEAD.FEATURE_EXTRACTOR 71 | ] 72 | return func(cfg, in_channels) 73 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/mask_head/roi_mask_predictors.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from torch import nn 3 | from torch.nn import functional as F 4 | 5 | from maskrcnn_benchmark.layers import Conv2d 6 | from maskrcnn_benchmark.layers import ConvTranspose2d 7 | from maskrcnn_benchmark.modeling import registry 8 | 9 | 10 | @registry.ROI_MASK_PREDICTOR.register("MaskRCNNC4Predictor") 11 | class MaskRCNNC4Predictor(nn.Module): 12 | def __init__(self, cfg, in_channels): 13 | super(MaskRCNNC4Predictor, self).__init__() 14 | num_classes = cfg.MODEL.ROI_BOX_HEAD.NUM_CLASSES 15 | dim_reduced = cfg.MODEL.ROI_MASK_HEAD.CONV_LAYERS[-1] 16 | num_inputs = in_channels 17 | 18 | self.conv5_mask = ConvTranspose2d(num_inputs, dim_reduced, 2, 2, 0) 19 | self.mask_fcn_logits = Conv2d(dim_reduced, num_classes, 1, 1, 0) 20 | 21 | for name, param in self.named_parameters(): 22 | if "bias" in name: 23 | nn.init.constant_(param, 0) 24 | elif "weight" in name: 25 | # Caffe2 implementation uses MSRAFill, which in fact 26 | # corresponds to kaiming_normal_ in PyTorch 27 | nn.init.kaiming_normal_(param, mode="fan_out", nonlinearity="relu") 28 | 29 | def forward(self, x): 30 | x = F.relu(self.conv5_mask(x)) 31 | return self.mask_fcn_logits(x) 32 | 33 | 34 | @registry.ROI_MASK_PREDICTOR.register("MaskRCNNConv1x1Predictor") 35 | class MaskRCNNConv1x1Predictor(nn.Module): 36 | def __init__(self, cfg, in_channels): 37 | super(MaskRCNNConv1x1Predictor, self).__init__() 38 | num_classes = cfg.MODEL.ROI_BOX_HEAD.NUM_CLASSES 39 | num_inputs = in_channels 40 | 41 | self.mask_fcn_logits = Conv2d(num_inputs, num_classes, 1, 1, 0) 42 | 43 | for name, param in self.named_parameters(): 44 | if "bias" in name: 45 | nn.init.constant_(param, 0) 46 | elif "weight" in name: 47 | # Caffe2 implementation uses MSRAFill, which in fact 48 | # corresponds to kaiming_normal_ in PyTorch 49 | nn.init.kaiming_normal_(param, mode="fan_out", nonlinearity="relu") 50 | 51 | def forward(self, x): 52 | return self.mask_fcn_logits(x) 53 | 54 | 55 | def make_roi_mask_predictor(cfg, in_channels): 56 | func = registry.ROI_MASK_PREDICTOR[cfg.MODEL.ROI_MASK_HEAD.PREDICTOR] 57 | return func(cfg, in_channels) 58 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/relation_head/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/relation_head/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/relation_head/rel_proposal_network/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/roi_heads/relation_head/rel_proposal_network/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/rpn/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | # from .rpn import build_rpn 3 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/rpn/retinanet/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/rpn/retinanet/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/rpn/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | """ 3 | Utility functions minipulating the prediction layers 4 | """ 5 | 6 | from ..utils import cat 7 | 8 | import torch 9 | 10 | def permute_and_flatten(layer, N, A, C, H, W): 11 | layer = layer.view(N, -1, C, H, W) 12 | layer = layer.permute(0, 3, 4, 1, 2) 13 | layer = layer.reshape(N, -1, C) 14 | return layer 15 | 16 | 17 | def concat_box_prediction_layers(box_cls, box_regression): 18 | box_cls_flattened = [] 19 | box_regression_flattened = [] 20 | # for each feature level, permute the outputs to make them be in the 21 | # same format as the labels. Note that the labels are computed for 22 | # all feature levels concatenated, so we keep the same representation 23 | # for the objectness and the box_regression 24 | for box_cls_per_level, box_regression_per_level in zip( 25 | box_cls, box_regression 26 | ): 27 | N, AxC, H, W = box_cls_per_level.shape 28 | Ax4 = box_regression_per_level.shape[1] 29 | A = Ax4 // 4 30 | C = AxC // A 31 | box_cls_per_level = permute_and_flatten( 32 | box_cls_per_level, N, A, C, H, W 33 | ) 34 | box_cls_flattened.append(box_cls_per_level) 35 | 36 | box_regression_per_level = permute_and_flatten( 37 | box_regression_per_level, N, A, 4, H, W 38 | ) 39 | box_regression_flattened.append(box_regression_per_level) 40 | # concatenate on the first dimension (representing the feature levels), to 41 | # take into account the way the labels were generated (with all feature maps 42 | # being concatenated as well) 43 | box_cls = cat(box_cls_flattened, dim=1).reshape(-1, C) 44 | box_regression = cat(box_regression_flattened, dim=1).reshape(-1, 4) 45 | return box_cls, box_regression 46 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/modeling/utils.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | """ 3 | Miscellaneous utility functions 4 | """ 5 | 6 | import torch 7 | 8 | 9 | def cat(tensors, dim=0): 10 | """ 11 | Efficient version of torch.cat that avoids a copy if there is only a single element in a list 12 | """ 13 | assert isinstance(tensors, (list, tuple)) 14 | if len(tensors) == 1: 15 | return tensors[0] 16 | return torch.cat(tensors, dim) 17 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/solver/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from .build import make_optimizer 3 | from .build import make_lr_scheduler 4 | from .lr_scheduler import WarmupMultiStepLR, WarmupReduceLROnPlateau 5 | 6 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/solver/build.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | 4 | from .lr_scheduler import WarmupMultiStepLR, WarmupReduceLROnPlateau 5 | 6 | 7 | def make_optimizer(cfg, model, logger, slow_heads=None, slow_ratio=5.0, rl_factor=1.0): 8 | params = [] 9 | for key, value in model.named_parameters(): 10 | if not value.requires_grad: 11 | continue 12 | lr = cfg.SOLVER.BASE_LR 13 | weight_decay = cfg.SOLVER.WEIGHT_DECAY 14 | if "bias" in key: 15 | lr = cfg.SOLVER.BASE_LR * cfg.SOLVER.BIAS_LR_FACTOR 16 | weight_decay = cfg.SOLVER.WEIGHT_DECAY_BIAS 17 | if slow_heads is not None: 18 | for item in slow_heads: 19 | if item in key: 20 | logger.info("SLOW HEADS: {} is slow down by ratio of {}.".format(key, str(slow_ratio))) 21 | lr = lr / slow_ratio 22 | break 23 | params += [{"params": [value], "lr": lr * rl_factor, "weight_decay": weight_decay}] 24 | 25 | optimizer = torch.optim.SGD(params, lr=cfg.SOLVER.BASE_LR, momentum=cfg.SOLVER.MOMENTUM) 26 | return optimizer 27 | 28 | 29 | def make_lr_scheduler(cfg, optimizer, logger=None): 30 | if cfg.SOLVER.SCHEDULE.TYPE == "WarmupMultiStepLR": 31 | return WarmupMultiStepLR( 32 | optimizer, 33 | cfg.SOLVER.STEPS, 34 | cfg.SOLVER.GAMMA, 35 | warmup_factor=cfg.SOLVER.WARMUP_FACTOR, 36 | warmup_iters=cfg.SOLVER.WARMUP_ITERS, 37 | warmup_method=cfg.SOLVER.WARMUP_METHOD, 38 | ) 39 | 40 | elif cfg.SOLVER.SCHEDULE.TYPE == "WarmupReduceLROnPlateau": 41 | return WarmupReduceLROnPlateau( 42 | optimizer, 43 | cfg.SOLVER.SCHEDULE.FACTOR, 44 | warmup_factor=cfg.SOLVER.WARMUP_FACTOR, 45 | warmup_iters=cfg.SOLVER.WARMUP_ITERS, 46 | warmup_method=cfg.SOLVER.WARMUP_METHOD, 47 | patience=cfg.SOLVER.SCHEDULE.PATIENCE, 48 | threshold=cfg.SOLVER.SCHEDULE.THRESHOLD, 49 | cooldown=cfg.SOLVER.SCHEDULE.COOLDOWN, 50 | logger=logger, 51 | ) 52 | 53 | else: 54 | raise ValueError("Invalid Schedule Type") 55 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/structures/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/structures/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/structures/image_list.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from __future__ import division 3 | 4 | import torch 5 | 6 | 7 | class ImageList(object): 8 | """ 9 | Structure that holds a list of images (of possibly 10 | varying sizes) as a single tensor. 11 | This works by padding the images to the same size, 12 | and storing in a field the original sizes of each image 13 | """ 14 | 15 | def __init__(self, tensors, image_sizes): 16 | """ 17 | Arguments: 18 | tensors (tensor) 19 | image_sizes (list[tuple[int, int]]) 20 | """ 21 | self.tensors = tensors 22 | self.image_sizes = image_sizes 23 | 24 | def to(self, *args, **kwargs): 25 | cast_tensor = self.tensors.to(*args, **kwargs) 26 | return ImageList(cast_tensor, self.image_sizes) 27 | 28 | 29 | def to_image_list(tensors, size_divisible=0): 30 | """ 31 | tensors can be an ImageList, a torch.Tensor or 32 | an iterable of Tensors. It can't be a numpy array. 33 | When tensors is an iterable of Tensors, it pads 34 | the Tensors with zeros so that they have the same 35 | shape 36 | """ 37 | if isinstance(tensors, torch.Tensor) and size_divisible > 0: 38 | tensors = [tensors] 39 | 40 | if isinstance(tensors, ImageList): 41 | return tensors 42 | elif isinstance(tensors, torch.Tensor): 43 | # single tensor shape can be inferred 44 | if tensors.dim() == 3: 45 | tensors = tensors[None] 46 | assert tensors.dim() == 4 47 | image_sizes = [tensor.shape[-2:] for tensor in tensors] 48 | return ImageList(tensors, image_sizes) 49 | elif isinstance(tensors, (tuple, list)): 50 | max_size = tuple(max(s) for s in zip(*[img.shape for img in tensors])) 51 | 52 | # TODO Ideally, just remove this and let me model handle arbitrary 53 | # input sizs 54 | if size_divisible > 0: 55 | import math 56 | 57 | stride = size_divisible 58 | max_size = list(max_size) 59 | max_size[1] = int(math.ceil(max_size[1] / stride) * stride) 60 | max_size[2] = int(math.ceil(max_size[2] / stride) * stride) 61 | max_size = tuple(max_size) 62 | 63 | batch_shape = (len(tensors),) + max_size 64 | batched_imgs = tensors[0].new(*batch_shape).zero_() 65 | for img, pad_img in zip(tensors, batched_imgs): 66 | pad_img[: img.shape[0], : img.shape[1], : img.shape[2]].copy_(img) 67 | 68 | image_sizes = [im.shape[-2:] for im in tensors] 69 | 70 | return ImageList(batched_imgs, image_sizes) 71 | else: 72 | raise TypeError("Unsupported type for to_image_list: {}".format(type(tensors))) 73 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/README.md: -------------------------------------------------------------------------------- 1 | # Utility functions 2 | 3 | This folder contain utility functions that are not used in the 4 | core library, but are useful for building models or training 5 | code using the config system. 6 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Multimodal-Commonsense-and-Task/Multimodal-Graph-Representation/8b066bb08173aa641fb259359cd4b4efa4ec4319/Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/__init__.py -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/collect_env.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import PIL 3 | 4 | from torch.utils.collect_env import get_pretty_env_info 5 | 6 | 7 | def get_pil_version(): 8 | return "\n Pillow ({})".format(PIL.__version__) 9 | 10 | 11 | def collect_env_info(): 12 | env_str = get_pretty_env_info() 13 | env_str += get_pil_version() 14 | return env_str 15 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/cv2_util.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module for cv2 utility functions and maintaining version compatibility 3 | between 3.x and 4.x 4 | """ 5 | import cv2 6 | 7 | 8 | def findContours(*args, **kwargs): 9 | """ 10 | Wraps cv2.findContours to maintain compatiblity between versions 11 | 3 and 4 12 | 13 | Returns: 14 | contours, hierarchy 15 | """ 16 | if cv2.__version__.startswith('4'): 17 | contours, hierarchy = cv2.findContours(*args, **kwargs) 18 | elif cv2.__version__.startswith('3'): 19 | _, contours, hierarchy = cv2.findContours(*args, **kwargs) 20 | else: 21 | raise AssertionError( 22 | 'cv2 must be either version 3 or 4 to call this method') 23 | 24 | return contours, hierarchy 25 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/env.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import os 3 | 4 | from maskrcnn_benchmark.utils.imports import import_file 5 | 6 | 7 | def setup_environment(): 8 | """Perform environment setup work. The default setup is a no-op, but this 9 | function allows the user to specify a Python source file that performs 10 | custom setup work that may be necessary to their computing environment. 11 | """ 12 | custom_module_path = os.environ.get("TORCH_DETECTRON_ENV_MODULE") 13 | if custom_module_path: 14 | setup_custom_environment(custom_module_path) 15 | else: 16 | # The default setup is a no-op 17 | pass 18 | 19 | 20 | def setup_custom_environment(custom_module_path): 21 | """Load custom environment setup from a Python source file and run the setup 22 | function. 23 | """ 24 | module = import_file("maskrcnn_benchmark.utils.env.custom_module", custom_module_path) 25 | assert hasattr(module, "setup_environment") and callable( 26 | module.setup_environment 27 | ), ( 28 | "Custom environment module defined in {} does not have the " 29 | "required callable attribute 'setup_environment'." 30 | ).format( 31 | custom_module_path 32 | ) 33 | module.setup_environment() 34 | 35 | 36 | # Force environment setup when this module is imported 37 | setup_environment() 38 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/global_buffer.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | import pickle 3 | import torch 4 | import os 5 | 6 | from maskrcnn_benchmark.utils.comm import is_main_process, get_world_size, all_gather, synchronize 7 | from maskrcnn_benchmark.config import cfg 8 | 9 | def singleton(cls): 10 | _instance = {} 11 | 12 | def inner(): 13 | if cls not in _instance: 14 | _instance[cls] = cls() 15 | return _instance[cls] 16 | return inner 17 | 18 | 19 | @singleton 20 | class _GlobalBuffer(): 21 | """a singleton buffer for store data in anywhere of program 22 | """ 23 | def __init__(self ): 24 | self.multi_proc = (get_world_size() > 1) 25 | self.data = defaultdict(list) 26 | 27 | def add_data(self, key, val): 28 | if not isinstance(val, torch.Tensor): 29 | val = torch.Tensor(val) 30 | else: 31 | val = val.detach() 32 | 33 | val = torch.cat(all_gather(val)) 34 | 35 | if not is_main_process(): 36 | del val 37 | return 38 | self.data[key].append(val.cpu().numpy()) 39 | 40 | def __str__(self): 41 | ret_str = f"Buffer contains data: (key, value type)\n" 42 | for k, v in self.data.items(): 43 | ret_str += f" {k}, {type(v).__name__}\n" 44 | ret_str += f"id {id(self)}" 45 | return ret_str 46 | 47 | 48 | def store_data(k, v, ): 49 | if cfg.GLOBAL_BUFFER_ON: 50 | buffer = _GlobalBuffer() 51 | buffer.add_data(k, v) 52 | synchronize() 53 | 54 | 55 | def save_buffer(output_dir): 56 | if cfg.GLOBAL_BUFFER_ON: 57 | if is_main_process(): 58 | buffer = _GlobalBuffer() 59 | with open(os.path.join(output_dir, "inter_data_buffer.pkl"), 'wb') as f: 60 | pickle.dump(buffer.data, f) 61 | 62 | print("save buffer:", str(buffer)) 63 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/imports.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | import torch 3 | 4 | # if torch._six.PY3: 5 | import importlib 6 | import importlib.util 7 | import sys 8 | 9 | 10 | # from https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa 11 | def import_file(module_name, file_path, make_importable=False): 12 | spec = importlib.util.spec_from_file_location(module_name, file_path) 13 | module = importlib.util.module_from_spec(spec) 14 | spec.loader.exec_module(module) 15 | if make_importable: 16 | sys.modules[module_name] = module 17 | return module 18 | # else: 19 | # import imp 20 | 21 | # def import_file(module_name, file_path, make_importable=None): 22 | # module = imp.load_source(module_name, file_path) 23 | # return module 24 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/metric_logger.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | from collections import defaultdict 3 | from collections import deque 4 | 5 | import torch 6 | 7 | 8 | class SmoothedValue(object): 9 | """Track a series of values and provide access to smoothed values over a 10 | window or the global series average. 11 | """ 12 | 13 | def __init__(self, window_size=20): 14 | self.deque = deque(maxlen=window_size) 15 | # self.series = [] 16 | self.total = 0.0 17 | self.count = 0 18 | 19 | def update(self, value): 20 | self.deque.append(value) 21 | # self.series.append(value) 22 | self.count += 1 23 | self.total += value 24 | 25 | @property 26 | def median(self): 27 | d = torch.tensor(list(self.deque)) 28 | return d.median().item() 29 | 30 | @property 31 | def avg(self): 32 | d = torch.tensor(list(self.deque)) 33 | return d.mean().item() 34 | 35 | @property 36 | def global_avg(self): 37 | return self.total / self.count 38 | 39 | 40 | class MetricLogger(object): 41 | def __init__(self, delimiter="\t"): 42 | self.meters = defaultdict(SmoothedValue) 43 | self.delimiter = delimiter 44 | 45 | def update(self, **kwargs): 46 | for k, v in kwargs.items(): 47 | if isinstance(v, torch.Tensor): 48 | v = v.item() 49 | assert isinstance(v, (float, int)) 50 | self.meters[k].update(v) 51 | 52 | def __getattr__(self, attr): 53 | if attr in self.meters: 54 | return self.meters[attr] 55 | if attr in self.__dict__: 56 | return self.__dict__[attr] 57 | raise AttributeError("'{}' object has no attribute '{}'".format( 58 | type(self).__name__, attr)) 59 | 60 | def __str__(self): 61 | loss_str = [] 62 | for name, meter in self.meters.items(): 63 | loss_str.append( 64 | "{}: {:.4f} ({:.4f})".format(name, meter.median, meter.global_avg) 65 | ) 66 | return self.delimiter.join(loss_str) 67 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/registry.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | 3 | 4 | def _register_generic(module_dict, module_name, module): 5 | assert module_name not in module_dict 6 | module_dict[module_name] = module 7 | 8 | 9 | class Registry(dict): 10 | ''' 11 | A helper class for managing registering modules, it extends a dictionary 12 | and provides a register functions. 13 | 14 | Eg. creeting a registry: 15 | some_registry = Registry({"default": default_module}) 16 | 17 | There're two ways of registering new modules: 18 | 1): normal way is just calling register function: 19 | def foo(): 20 | ... 21 | some_registry.register("foo_module", foo) 22 | 2): used as decorator when declaring the module: 23 | @some_registry.register("foo_module") 24 | @some_registry.register("foo_modeul_nickname") 25 | def foo(): 26 | ... 27 | 28 | Access of module is just like using a dictionary, eg: 29 | f = some_registry["foo_modeul"] 30 | ''' 31 | def __init__(self, *args, **kwargs): 32 | super(Registry, self).__init__(*args, **kwargs) 33 | 34 | def register(self, module_name, module=None): 35 | # used as function call 36 | if module is not None: 37 | _register_generic(self, module_name, module) 38 | return 39 | 40 | # used as decorator 41 | def register_fn(fn): 42 | _register_generic(self, module_name, fn) 43 | return fn 44 | 45 | return register_fn 46 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/maskrcnn_benchmark/utils/timer.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | 3 | 4 | import time 5 | import datetime 6 | 7 | 8 | class Timer(object): 9 | def __init__(self): 10 | self.reset() 11 | 12 | @property 13 | def average_time(self): 14 | return self.total_time / self.calls if self.calls > 0 else 0.0 15 | 16 | def tic(self): 17 | # using time.time instead of time.clock because time time.clock 18 | # does not normalize for multithreading 19 | self.start_time = time.time() 20 | 21 | def toc(self, average=True): 22 | self.add(time.time() - self.start_time) 23 | if average: 24 | return self.average_time 25 | else: 26 | return self.diff 27 | 28 | def add(self, time_diff): 29 | self.diff = time_diff 30 | self.total_time += self.diff 31 | self.calls += 1 32 | 33 | def reset(self): 34 | self.total_time = 0.0 35 | self.calls = 0 36 | self.start_time = 0.0 37 | self.diff = 0.0 38 | 39 | def avg_time_str(self): 40 | time_str = str(datetime.timedelta(seconds=self.average_time)) 41 | return time_str 42 | 43 | 44 | def get_time_str(time_diff): 45 | time_str = str(datetime.timedelta(seconds=time_diff)) 46 | return time_str 47 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/predcls/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 21 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 22 | TEST.METRIC "R" \ 23 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 26 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 27 | OUTPUT_DIR $OUTPATH \ 28 | GLOVE_DIR $GLOVE_DIR 29 | else 30 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 31 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 32 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 33 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 34 | SOLVER.IMS_PER_BATCH 6 \ 35 | TEST.IMS_PER_BATCH 1 \ 36 | SOLVER.MAX_ITER 50000 \ 37 | SOLVER.VAL_PERIOD 2000 \ 38 | SOLVER.CHECKPOINT_PERIOD 2000 \ 39 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 40 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 41 | TEST.METRIC "R" \ 42 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 43 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 44 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 45 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 46 | OUTPUT_DIR $OUTPATH \ 47 | GLOVE_DIR $GLOVE_DIR 48 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/bilvl/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/predcls/bilvl_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | ALPHA_DEC=0.4 7 | ALPHA_INC=0.4 8 | MODEL_WEIGHT_PATH="checkpoints/50/bgnn/predcls/bilvl/model_???.pth" # Path of pretrained model 9 | mkdir -p $OUTPATH 10 | 11 | if $mutli_gpu;then 12 | python -m torch.distributed.launch \ 13 | --master_port 10093 --nproc_per_node=$num_gpu \ 14 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 15 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 17 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 18 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 19 | SOLVER.IMS_PER_BATCH 12 \ 20 | TEST.IMS_PER_BATCH 2 \ 21 | SOLVER.MAX_ITER 50000 \ 22 | SOLVER.VAL_PERIOD 2000 \ 23 | SOLVER.CHECKPOINT_PERIOD 2000 \ 24 | OUTPUT_DIR $OUTPATH \ 25 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 26 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 27 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 28 | GLOVE_DIR $GLOVE_DIR \ 29 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 30 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 31 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 32 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 36 | else 37 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 39 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 40 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 41 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 42 | SOLVER.IMS_PER_BATCH 6 \ 43 | TEST.IMS_PER_BATCH 1 \ 44 | SOLVER.MAX_ITER 50000 \ 45 | SOLVER.VAL_PERIOD 2000 \ 46 | SOLVER.CHECKPOINT_PERIOD 2000 \ 47 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 48 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 49 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 50 | OUTPUT_DIR $OUTPATH \ 51 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 52 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 53 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 54 | GLOVE_DIR $GLOVE_DIR \ 55 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 57 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 58 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 59 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/ie_trans/relabel/combine.sh: -------------------------------------------------------------------------------- 1 | OUTPATH="checkpoints/50/motif/predcls/ie_trans" 2 | mkdir -p $OUTPATH 3 | cp tools/ietrans/combine.py $OUTPATH 4 | cd $OUTPATH 5 | python combine.py 6 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/ie_trans/relabel/external.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" 2 | OUTPATH="checkpoints/50/bgnn/predcls/ie_trans" 3 | MODEL_WEIGHT_PATH="checkpoints/50/bgnn/predcls/ie_trans/pretrain/model_???.pth" # Insert the pretraiend model weight on predcls task 4 | GLOVE_DIR="Glove" # Glove directory 5 | 6 | mkdir -p $OUTPATH 7 | 8 | 9 | python tools/external_relabel.py --config-file "configs/wsup-50_external.yaml" \ 10 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 11 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 13 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 14 | SOLVER.IMS_PER_BATCH 6 TEST.IMS_PER_BATCH 1 \ 15 | SOLVER.MAX_ITER 50000 \ 16 | SOLVER.VAL_PERIOD 2000 \ 17 | SOLVER.CHECKPOINT_PERIOD 2000 \ 18 | OUTPUT_DIR $OUTPATH \ 19 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 20 | SOLVER.PRE_VAL False \ 21 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 22 | GLOVE_DIR $GLOVE_DIR \ 23 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 24 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 25 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.PRETRAIN_RELNESS_MODULE False \ 26 | WSUPERVISE.DATASET ExTransDataset EM.MODE E WSUPERVISE.SPECIFIED_DATA_FILE datasets_vg/vg/50/vg_clip_logits.pk 27 | 28 | 29 | cp tools/ietrans/external_cut.py $OUTPATH 30 | cp tools/ietrans/na_score_rank.py $OUTPATH 31 | cd $OUTPATH 32 | python na_score_rank.py 33 | python external_cut.py 1.0 # use all relabeled DS data 34 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/ie_trans/relabel/internal.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="6" 2 | OUTPATH="checkpoints/50/bgnn/predcls/ie_trans" # put the pre-trained model's path 3 | MODEL_WEIGHT_PATH="checkpoints/50/bgnn/predcls/ie_trans/pretrain/model_???.pth" # Insert the pretraiend model weight on predcls task 4 | 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | 8 | mkdir -p $OUTPATH 9 | 10 | python tools/internal_relabel.py --config-file "configs/wsup-50_internal.yaml" \ 11 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 6 TEST.IMS_PER_BATCH 1 \ 16 | SOLVER.MAX_ITER 50000 \ 17 | SOLVER.VAL_PERIOD 2000 \ 18 | SOLVER.CHECKPOINT_PERIOD 2000 \ 19 | OUTPUT_DIR $OUTPATH \ 20 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 21 | SOLVER.PRE_VAL False \ 22 | GLOVE_DIR $GLOVE_DIR \ 23 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 24 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 25 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 26 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 27 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.PRETRAIN_RELNESS_MODULE False \ 28 | WSUPERVISE.DATASET InTransDataset EM.MODE E WSUPERVISE.SPECIFIED_DATA_FILE datasets_vg/vg/50/vg_sup_data.pk 29 | 30 | 31 | 32 | cp tools/ietrans/internal_cut.py $OUTPATH 33 | cd $OUTPATH 34 | python internal_cut.py 0.7 35 | 36 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/ie_trans/relabel/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/predcls/ie_trans/pretrain" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 6 \ 16 | TEST.IMS_PER_BATCH 1 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 21 | TEST.METRIC "R" \ 22 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 23 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 24 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 25 | OUTPUT_DIR $OUTPATH \ 26 | GLOVE_DIR $GLOVE_DIR \ 27 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 28 | else 29 | python tools/relation_train_net.py --config-file "configs/sup-50_motif_vctree.yaml" \ 30 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 31 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 32 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 33 | SOLVER.IMS_PER_BATCH 6 \ 34 | TEST.IMS_PER_BATCH 1 \ 35 | SOLVER.MAX_ITER 50000 \ 36 | SOLVER.VAL_PERIOD 2000 \ 37 | SOLVER.CHECKPOINT_PERIOD 2000 \ 38 | TEST.METRIC "R" \ 39 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 40 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 41 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 42 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 43 | OUTPUT_DIR $OUTPATH \ 44 | GLOVE_DIR $GLOVE_DIR \ 45 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 46 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/bgnn/predcls/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/bgnn/BGNN_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | DATASETS.TRAIN \(\"50DS_VG_VGKB_train\",\) \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 19 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 20 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 21 | SOLVER.IMS_PER_BATCH 12 \ 22 | TEST.IMS_PER_BATCH 2 \ 23 | SOLVER.MAX_ITER 50000 \ 24 | SOLVER.VAL_PERIOD 2000 \ 25 | SOLVER.CHECKPOINT_PERIOD 2000 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 28 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 29 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 30 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 33 | EM.MODE "x" 34 | else 35 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 36 | DATASETS.TRAIN \(\"50DS_VG_VGKB_train\",\) \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 39 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 40 | SOLVER.IMS_PER_BATCH 6 \ 41 | TEST.IMS_PER_BATCH 1 \ 42 | SOLVER.MAX_ITER 50000 \ 43 | SOLVER.VAL_PERIOD 2000 \ 44 | SOLVER.CHECKPOINT_PERIOD 2000 \ 45 | OUTPUT_DIR $OUTPATH \ 46 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 47 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 48 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 49 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 50 | GLOVE_DIR $GLOVE_DIR \ 51 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 52 | EM.MODE "x" 53 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/predcls/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/predcls/st_sgg" # save directory 5 | GLOVE_DIR="Glove 6 | SPECIFIED_PATH="datasets/50/bgnn/BGNN_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/bgnn/predcls/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | 11 | mkdir -p $OUTPATH 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 19 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 20 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 21 | SOLVER.IMS_PER_BATCH 12 \ 22 | TEST.IMS_PER_BATCH 2 \ 23 | SOLVER.MAX_ITER 50000 \ 24 | SOLVER.VAL_PERIOD 2000 \ 25 | SOLVER.CHECKPOINT_PERIOD 2000 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 28 | SOLVER.PRE_VAL False \ 29 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 30 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 31 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 32 | GLOVE_DIR $GLOVE_DIR \ 33 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 34 | EM.MODE "x" \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 36 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 37 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 38 | else 39 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 41 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 42 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 43 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 44 | SOLVER.IMS_PER_BATCH 6 \ 45 | TEST.IMS_PER_BATCH 1 \ 46 | SOLVER.MAX_ITER 50000 \ 47 | SOLVER.VAL_PERIOD 2000 \ 48 | SOLVER.CHECKPOINT_PERIOD 2000 \ 49 | OUTPUT_DIR $OUTPATH \ 50 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 51 | SOLVER.PRE_VAL False \ 52 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 53 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 54 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 55 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 56 | GLOVE_DIR $GLOVE_DIR \ 57 | EM.MODE "x" \ 58 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 59 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 60 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 61 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/sgcls/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/sgcls/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 21 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 22 | TEST.METRIC "R" \ 23 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 27 | OUTPUT_DIR $OUTPATH \ 28 | GLOVE_DIR $GLOVE_DIR 29 | else 30 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 31 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 32 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 33 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 34 | SOLVER.IMS_PER_BATCH 6 \ 35 | TEST.IMS_PER_BATCH 1 \ 36 | SOLVER.MAX_ITER 50000 \ 37 | SOLVER.VAL_PERIOD 2000 \ 38 | SOLVER.CHECKPOINT_PERIOD 2000 \ 39 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 40 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 41 | TEST.METRIC "R" \ 42 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 43 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 44 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 45 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 46 | SOLVER.PRE_VAL False \ 47 | OUTPUT_DIR $OUTPATH \ 48 | GLOVE_DIR $GLOVE_DIR 49 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/sgcls/bilvl/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/sgcls/bilvl_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | ALPHA_DEC=0.4 7 | ALPHA_INC=0.4 8 | MODEL_WEIGHT_PATH="checkpoints/50/bgnn/sgcls/bilvl/model_???.pth" # Path of pretrained model 9 | mkdir -p $OUTPATH 10 | 11 | if $mutli_gpu;then 12 | python -m torch.distributed.launch \ 13 | --master_port 10093 --nproc_per_node=$num_gpu \ 14 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 15 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 17 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 18 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 19 | SOLVER.IMS_PER_BATCH 12 \ 20 | TEST.IMS_PER_BATCH 2 \ 21 | SOLVER.MAX_ITER 50000 \ 22 | SOLVER.VAL_PERIOD 2000 \ 23 | SOLVER.CHECKPOINT_PERIOD 2000 \ 24 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 25 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 26 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 27 | OUTPUT_DIR $OUTPATH \ 28 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 29 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 30 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 35 | else 36 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 39 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 40 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 41 | SOLVER.IMS_PER_BATCH 6 \ 42 | TEST.IMS_PER_BATCH 1 \ 43 | SOLVER.MAX_ITER 50000 \ 44 | SOLVER.VAL_PERIOD 2000 \ 45 | SOLVER.CHECKPOINT_PERIOD 2000 \ 46 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 47 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 48 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 49 | OUTPUT_DIR $OUTPATH \ 50 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 51 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 52 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 53 | GLOVE_DIR $GLOVE_DIR \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 55 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 57 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/sgcls/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/bgnn/sgcls/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/bgnn/BGNN_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | GLOVE_DIR $GLOVE_DIR \ 28 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 29 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 30 | WSUPERVISE.DATASET InTransDataset \ 31 | EM.MODE "x" 32 | else 33 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 34 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 35 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 36 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 37 | SOLVER.IMS_PER_BATCH 6 \ 38 | TEST.IMS_PER_BATCH 1 \ 39 | SOLVER.MAX_ITER 50000 \ 40 | SOLVER.VAL_PERIOD 2000 \ 41 | SOLVER.CHECKPOINT_PERIOD 2000 \ 42 | OUTPUT_DIR $OUTPATH \ 43 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 44 | GLOVE_DIR $GLOVE_DIR \ 45 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 46 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 47 | EM.MODE "x" 48 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/sgcls/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/sgcls/st_sgg" # save directory 5 | GLOVE_DIR="Glove 6 | SPECIFIED_PATH="datasets/50/bgnn/BGNN_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/bgnn/sgcls/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | mkdir -p $OUTPATH 11 | 12 | if $mutli_gpu;then 13 | python -m torch.distributed.launch \ 14 | --master_port 10093 --nproc_per_node=$num_gpu \ 15 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 18 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 28 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 29 | EM.MODE "x" \ 30 | GLOVE_DIR $GLOVE_DIR \ 31 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 34 | else 35 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 36 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 38 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 39 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 40 | SOLVER.IMS_PER_BATCH 6 \ 41 | TEST.IMS_PER_BATCH 1 \ 42 | SOLVER.MAX_ITER 50000 \ 43 | SOLVER.VAL_PERIOD 2000 \ 44 | SOLVER.CHECKPOINT_PERIOD 2000 \ 45 | OUTPUT_DIR $OUTPATH \ 46 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 47 | SOLVER.PRE_VAL False \ 48 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 49 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 50 | EM.MODE "x" \ 51 | GLOVE_DIR $GLOVE_DIR \ 52 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 53 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 55 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/sgdet/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/sgdet/bilvl" # save directory 5 | GLOVE_DIR="Glove 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 21 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 22 | TEST.METRIC "R" \ 23 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 27 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 28 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 29 | OUTPUT_DIR $OUTPATH \ 30 | GLOVE_DIR $GLOVE_DIR 31 | else 32 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 33 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 34 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 35 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 36 | SOLVER.IMS_PER_BATCH 6 \ 37 | TEST.IMS_PER_BATCH 1 \ 38 | SOLVER.MAX_ITER 50000 \ 39 | SOLVER.VAL_PERIOD 2000 \ 40 | SOLVER.CHECKPOINT_PERIOD 2000 \ 41 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 42 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 43 | TEST.METRIC "R" \ 44 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 45 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 46 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 47 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 48 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 49 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 50 | OUTPUT_DIR $OUTPATH \ 51 | GLOVE_DIR $GLOVE_DIR 52 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/sgdet/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/bgnn/sgdet/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/bgnn/BGNN_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 27 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 28 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 29 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 30 | GLOVE_DIR $GLOVE_DIR \ 31 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 32 | EM.MODE "x" 33 | else 34 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 35 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 36 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 37 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_GSL \ 38 | SOLVER.IMS_PER_BATCH 6 \ 39 | TEST.IMS_PER_BATCH 1 \ 40 | SOLVER.MAX_ITER 50000 \ 41 | SOLVER.VAL_PERIOD 2000 \ 42 | SOLVER.CHECKPOINT_PERIOD 2000 \ 43 | OUTPUT_DIR $OUTPATH \ 44 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 45 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 46 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 47 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 48 | GLOVE_DIR $GLOVE_DIR \ 49 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 50 | EM.MODE "x" 51 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/bgnn/sgdet/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/bgnn/sgdet/st_sgg" # save directory 5 | GLOVE_DIR="Glove 6 | SPECIFIED_PATH="datasets/50/bgnn/BGNN_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/bgnn/sgdet/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | mkdir -p $OUTPATH 11 | 12 | if $mutli_gpu;then 13 | python -m torch.distributed.launch \ 14 | --master_port 10093 --nproc_per_node=$num_gpu \ 15 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 18 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 28 | WSUPERVISE.DATASET InTransDataset \ 29 | EM.MODE "x" \ 30 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 31 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 32 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 33 | GLOVE_DIR $GLOVE_DIR \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 36 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 37 | else 38 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 39 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 41 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 42 | MODEL.ROI_RELATION_HEAD.PREDICTOR BGNNPredictor_STSGG \ 43 | SOLVER.IMS_PER_BATCH 6 \ 44 | TEST.IMS_PER_BATCH 1 \ 45 | SOLVER.MAX_ITER 50000 \ 46 | SOLVER.VAL_PERIOD 2000 \ 47 | SOLVER.CHECKPOINT_PERIOD 2000 \ 48 | OUTPUT_DIR $OUTPATH \ 49 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 50 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 51 | EM.MODE "x" \ 52 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 53 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 54 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 55 | GLOVE_DIR $GLOVE_DIR \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 57 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 58 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 59 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/evaluation.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="1" # if using multi-gpu, put the multi gpu numbers, e.g., "2,3" 2 | num_gpu=1 # gpu number 3 | multi_gpu=false 4 | 5 | 6 | export checkpoint_list=("0028000") # Put the iteration number of trained model 7 | export output_dir="checkpoints/50/??" # Put the directory for evaluation 8 | 9 | if $multi_gpu;then 10 | for t in ${checkpoint_list[@]} 11 | do 12 | python -m torch.distributed.launch --master_port 10093 --nproc_per_node=$num_gpu \ 13 | tools/relation_test_net.py --config-file "${output_dir}/config.yml" \ 14 | TEST.IMS_PER_BATCH 2 \ 15 | OUTPUT_DIR ${output_dir} \ 16 | MODEL.WEIGHT "${output_dir}/model_${t}.pth" 17 | done 18 | else 19 | for t in ${checkpoint_list[@]} 20 | do 21 | python tools/relation_test_net.py --config-file "${output_dir}/config.yml" \ 22 | TEST.IMS_PER_BATCH 1 \ 23 | OUTPUT_DIR ${output_dir} \ 24 | MODEL.WEIGHT "${output_dir}/model_${t}.pth" 25 | done 26 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/evaluation4pretrained_model.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="1" # if using multi-gpu, put the multi gpu numbers, e.g., "2,3" 2 | num_gpu=1 # gpu number 3 | multi_gpu=false 4 | 5 | 6 | export output_dir="configs/evaluation_config/motif_stsgg_sgcls_eval" # Put the directory for evaluation 7 | 8 | if $multi_gpu;then 9 | python -m torch.distributed.launch --master_port 10093 --nproc_per_node=$num_gpu \ 10 | tools/relation_test_net.py --config-file "${output_dir}/config.yml" \ 11 | TEST.IMS_PER_BATCH 2 \ 12 | OUTPUT_DIR ${output_dir} 13 | else 14 | python tools/relation_test_net.py --config-file "${output_dir}/config.yml" \ 15 | TEST.IMS_PER_BATCH 1 \ 16 | OUTPUT_DIR ${output_dir} 17 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/predcls/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/predcls/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 21 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 22 | TEST.METRIC "R" \ 23 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 26 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 27 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 28 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 29 | OUTPUT_DIR $OUTPATH \ 30 | GLOVE_DIR $GLOVE_DIR 31 | else 32 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 33 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 34 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 35 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 36 | SOLVER.IMS_PER_BATCH 6 \ 37 | TEST.IMS_PER_BATCH 1 \ 38 | SOLVER.MAX_ITER 50000 \ 39 | SOLVER.VAL_PERIOD 2000 \ 40 | SOLVER.CHECKPOINT_PERIOD 2000 \ 41 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 42 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 43 | TEST.METRIC "R" \ 44 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 45 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 46 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 47 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 48 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 49 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 50 | OUTPUT_DIR $OUTPATH \ 51 | GLOVE_DIR $GLOVE_DIR 52 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/predcls/ie_trans/relabel/combine.sh: -------------------------------------------------------------------------------- 1 | OUTPATH="checkpoints/50/motif/predcls/ie_trans" 2 | mkdir -p $OUTPATH 3 | cp tools/ietrans/combine.py $OUTPATH 4 | cd $OUTPATH 5 | python combine.py 6 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/predcls/ie_trans/relabel/external.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" 2 | OUTPATH="checkpoints/50/hetsgg/predcls/ie_trans" 3 | MODEL_WEIGHT_PATH="checkpoints/50/hetsgg/predcls/ie_trans/pretrain/model_???.pth" # Insert the pretraiend model weight on predcls task 4 | GLOVE_DIR="Glove" # Glove directory 5 | 6 | mkdir -p $OUTPATH 7 | 8 | 9 | python tools/external_relabel.py --config-file "configs/wsup-50_external.yaml" \ 10 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 11 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 13 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 14 | SOLVER.IMS_PER_BATCH 6 TEST.IMS_PER_BATCH 1 \ 15 | SOLVER.MAX_ITER 50000 \ 16 | SOLVER.VAL_PERIOD 2000 \ 17 | SOLVER.CHECKPOINT_PERIOD 2000 \ 18 | OUTPUT_DIR $OUTPATH \ 19 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 20 | SOLVER.PRE_VAL False \ 21 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 22 | GLOVE_DIR $GLOVE_DIR \ 23 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 24 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 25 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.PRETRAIN_RELNESS_MODULE False \ 26 | WSUPERVISE.DATASET ExTransDataset EM.MODE E WSUPERVISE.SPECIFIED_DATA_FILE datasets_vg/vg/50/vg_clip_logits.pk 27 | 28 | 29 | cp tools/ietrans/external_cut.py $OUTPATH 30 | cp tools/ietrans/na_score_rank.py $OUTPATH 31 | cd $OUTPATH 32 | python na_score_rank.py 33 | python external_cut.py 1.0 # use all relabeled DS data 34 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/predcls/ie_trans/relabel/internal.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="6" 2 | OUTPATH="checkpoints/50/hetsgg/predcls/ie_trans" # put the pre-trained model's path 3 | MODEL_WEIGHT_PATH="checkpoints/50/hetsgg/predcls/ie_trans/pretrain/model_???.pth" # Insert the pretraiend model weight on predcls task 4 | 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | 8 | mkdir -p $OUTPATH 9 | 10 | python tools/internal_relabel.py --config-file "configs/wsup-50_internal.yaml" \ 11 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 6 TEST.IMS_PER_BATCH 1 \ 16 | SOLVER.MAX_ITER 50000 \ 17 | SOLVER.VAL_PERIOD 2000 \ 18 | SOLVER.CHECKPOINT_PERIOD 2000 \ 19 | OUTPUT_DIR $OUTPATH \ 20 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 21 | SOLVER.PRE_VAL False \ 22 | GLOVE_DIR $GLOVE_DIR \ 23 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 24 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 25 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 26 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 27 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.PRETRAIN_RELNESS_MODULE False \ 28 | WSUPERVISE.DATASET InTransDataset EM.MODE E WSUPERVISE.SPECIFIED_DATA_FILE datasets_vg/vg/50/vg_sup_data.pk 29 | 30 | 31 | 32 | cp tools/ietrans/internal_cut.py $OUTPATH 33 | cd $OUTPATH 34 | python internal_cut.py 0.7 35 | 36 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/predcls/ie_trans/relabel/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/predcls/ie_trans/pretrain" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 6 \ 16 | TEST.IMS_PER_BATCH 1 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | SOLVER.PRE_VAL False \ 21 | TEST.METRIC "R" \ 22 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 23 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 24 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 25 | OUTPUT_DIR $OUTPATH \ 26 | GLOVE_DIR $GLOVE_DIR \ 27 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 28 | else 29 | python tools/relation_train_net.py --config-file "configs/sup-50_motif_vctree.yaml" \ 30 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 31 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 32 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 33 | SOLVER.IMS_PER_BATCH 6 \ 34 | TEST.IMS_PER_BATCH 1 \ 35 | SOLVER.MAX_ITER 50000 \ 36 | SOLVER.VAL_PERIOD 2000 \ 37 | SOLVER.CHECKPOINT_PERIOD 2000 \ 38 | TEST.METRIC "R" \ 39 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 40 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 41 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 42 | SOLVER.PRE_VAL False \ 43 | OUTPUT_DIR $OUTPATH \ 44 | GLOVE_DIR $GLOVE_DIR \ 45 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 46 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/predcls/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/hetsgg/predcls/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/hetsgg/HetSGG_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | SOLVER.PRE_VAL False \ 28 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 29 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 30 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 33 | EM.MODE "x" 34 | else 35 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 36 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 38 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 39 | SOLVER.IMS_PER_BATCH 6 \ 40 | TEST.IMS_PER_BATCH 1 \ 41 | SOLVER.MAX_ITER 50000 \ 42 | SOLVER.VAL_PERIOD 2000 \ 43 | SOLVER.CHECKPOINT_PERIOD 2000 \ 44 | OUTPUT_DIR $OUTPATH \ 45 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 46 | SOLVER.PRE_VAL False \ 47 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 48 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 49 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 50 | GLOVE_DIR $GLOVE_DIR \ 51 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 52 | EM.MODE "x" 53 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/predcls/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/predcls/st_sgg" # save directory 5 | GLOVE_DIR="Glove 6 | SPECIFIED_PATH="datasets/50/hetsgg/HetSGG_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/hetsgg/predcls/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | 11 | mkdir -p $OUTPATH 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 19 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 20 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 21 | SOLVER.IMS_PER_BATCH 12 \ 22 | TEST.IMS_PER_BATCH 2 \ 23 | SOLVER.MAX_ITER 50000 \ 24 | SOLVER.VAL_PERIOD 2000 \ 25 | SOLVER.CHECKPOINT_PERIOD 2000 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 28 | SOLVER.PRE_VAL False \ 29 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 30 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 31 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 32 | GLOVE_DIR $GLOVE_DIR \ 33 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 34 | EM.MODE "x" \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 36 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 37 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 38 | else 39 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 41 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 42 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 43 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 44 | SOLVER.IMS_PER_BATCH 6 \ 45 | TEST.IMS_PER_BATCH 1 \ 46 | SOLVER.MAX_ITER 50000 \ 47 | SOLVER.VAL_PERIOD 2000 \ 48 | SOLVER.CHECKPOINT_PERIOD 2000 \ 49 | OUTPUT_DIR $OUTPATH \ 50 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 51 | SOLVER.PRE_VAL False \ 52 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 53 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 54 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 55 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 56 | GLOVE_DIR $GLOVE_DIR \ 57 | EM.MODE "x" \ 58 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 59 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 60 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 61 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/sgcls/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/sgcls/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 21 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 22 | TEST.METRIC "R" \ 23 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 27 | OUTPUT_DIR $OUTPATH \ 28 | GLOVE_DIR $GLOVE_DIR 29 | else 30 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 31 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 32 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 33 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 34 | SOLVER.IMS_PER_BATCH 6 \ 35 | TEST.IMS_PER_BATCH 1 \ 36 | SOLVER.MAX_ITER 50000 \ 37 | SOLVER.VAL_PERIOD 2000 \ 38 | SOLVER.CHECKPOINT_PERIOD 2000 \ 39 | TEST.METRIC "R" \ 40 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 41 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 42 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 43 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 44 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 45 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 46 | OUTPUT_DIR $OUTPATH \ 47 | GLOVE_DIR $GLOVE_DIR 48 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/sgcls/bilvl/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/sgcls/bilvl_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | ALPHA_DEC=0.4 7 | ALPHA_INC=0.4 8 | MODEL_WEIGHT_PATH="checkpoints/50/hetsgg/sgcls/bilvl/model_???.pth" # Path of pretrained model 9 | mkdir -p $OUTPATH 10 | 11 | if $mutli_gpu;then 12 | python -m torch.distributed.launch \ 13 | --master_port 10093 --nproc_per_node=$num_gpu \ 14 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 15 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 17 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 18 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 19 | SOLVER.IMS_PER_BATCH 12 \ 20 | TEST.IMS_PER_BATCH 2 \ 21 | SOLVER.MAX_ITER 50000 \ 22 | SOLVER.VAL_PERIOD 2000 \ 23 | SOLVER.CHECKPOINT_PERIOD 2000 \ 24 | OUTPUT_DIR $OUTPATH \ 25 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 26 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 27 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 28 | GLOVE_DIR $GLOVE_DIR \ 29 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 30 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 31 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 35 | else 36 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 39 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 40 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 41 | SOLVER.IMS_PER_BATCH 6 \ 42 | TEST.IMS_PER_BATCH 1 \ 43 | SOLVER.MAX_ITER 50000 \ 44 | SOLVER.VAL_PERIOD 2000 \ 45 | SOLVER.CHECKPOINT_PERIOD 2000 \ 46 | OUTPUT_DIR $OUTPATH \ 47 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 48 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 49 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 50 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 51 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 52 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 53 | GLOVE_DIR $GLOVE_DIR \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 55 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 57 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/sgcls/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/hetsgg/sgcls/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/hetsgg/HetSGG_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | SOLVER.PRE_VAL False \ 28 | GLOVE_DIR $GLOVE_DIR \ 29 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 30 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 31 | WSUPERVISE.DATASET InTransDataset \ 32 | EM.MODE "x" 33 | else 34 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 35 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 36 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 37 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 38 | SOLVER.IMS_PER_BATCH 6 \ 39 | TEST.IMS_PER_BATCH 1 \ 40 | SOLVER.MAX_ITER 50000 \ 41 | SOLVER.VAL_PERIOD 2000 \ 42 | SOLVER.CHECKPOINT_PERIOD 2000 \ 43 | OUTPUT_DIR $OUTPATH \ 44 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 45 | SOLVER.PRE_VAL False \ 46 | GLOVE_DIR $GLOVE_DIR \ 47 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 48 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 49 | EM.MODE "x" 50 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/sgcls/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/sgcls/st_sgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | SPECIFIED_PATH="datasets/50/hetsgg/HetSGG_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/hetsgg/sgcls/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | mkdir -p $OUTPATH 11 | 12 | if $mutli_gpu;then 13 | python -m torch.distributed.launch \ 14 | --master_port 10093 --nproc_per_node=$num_gpu \ 15 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 18 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | SOLVER.PRE_VAL False \ 28 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 29 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 30 | EM.MODE "x" \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 35 | else 36 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 39 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 40 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 41 | SOLVER.IMS_PER_BATCH 6 \ 42 | TEST.IMS_PER_BATCH 1 \ 43 | SOLVER.MAX_ITER 50000 \ 44 | SOLVER.VAL_PERIOD 2000 \ 45 | SOLVER.CHECKPOINT_PERIOD 2000 \ 46 | OUTPUT_DIR $OUTPATH \ 47 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 48 | SOLVER.PRE_VAL False \ 49 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 50 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 51 | EM.MODE "x" \ 52 | GLOVE_DIR $GLOVE_DIR \ 53 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 55 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 56 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/sgdet/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/sgdet/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 21 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 22 | TEST.METRIC "R" \ 23 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 27 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 28 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 29 | OUTPUT_DIR $OUTPATH \ 30 | GLOVE_DIR $GLOVE_DIR 31 | else 32 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 33 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 34 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 35 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 36 | SOLVER.IMS_PER_BATCH 6 \ 37 | TEST.IMS_PER_BATCH 1 \ 38 | SOLVER.MAX_ITER 50000 \ 39 | SOLVER.VAL_PERIOD 2000 \ 40 | SOLVER.CHECKPOINT_PERIOD 2000 \ 41 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 42 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 43 | TEST.METRIC "R" \ 44 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 45 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 46 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 47 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 48 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 49 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 50 | OUTPUT_DIR $OUTPATH \ 51 | GLOVE_DIR $GLOVE_DIR 52 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/sgdet/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/hetsgg/sgdet/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/hetsgg/HetSGG_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 27 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 28 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 29 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 30 | SOLVER.PRE_VAL False \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 33 | EM.MODE "x" 34 | else 35 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 36 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 38 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_GSL \ 39 | SOLVER.IMS_PER_BATCH 6 \ 40 | TEST.IMS_PER_BATCH 1 \ 41 | SOLVER.MAX_ITER 50000 \ 42 | SOLVER.VAL_PERIOD 2000 \ 43 | SOLVER.CHECKPOINT_PERIOD 2000 \ 44 | OUTPUT_DIR $OUTPATH \ 45 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 46 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 47 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 48 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 49 | SOLVER.PRE_VAL False \ 50 | GLOVE_DIR $GLOVE_DIR \ 51 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 52 | EM.MODE "x" 53 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/hetsgg/sgdet/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/hetsgg/sgdet/st_sgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | SPECIFIED_PATH="datasets/50/hetsgg/HetSGG_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/hetsgg/sgdet/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | mkdir -p $OUTPATH 11 | 12 | if $mutli_gpu;then 13 | python -m torch.distributed.launch \ 14 | --master_port 10093 --nproc_per_node=$num_gpu \ 15 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 18 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | SOLVER.PRE_VAL False \ 28 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 29 | WSUPERVISE.DATASET InTransDataset \ 30 | EM.MODE "x" \ 31 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 32 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 33 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 34 | GLOVE_DIR $GLOVE_DIR \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 36 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 37 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 38 | else 39 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 41 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 42 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 43 | MODEL.ROI_RELATION_HEAD.PREDICTOR HetSGGPredictor_STSGG \ 44 | SOLVER.IMS_PER_BATCH 6 \ 45 | TEST.IMS_PER_BATCH 1 \ 46 | SOLVER.MAX_ITER 50000 \ 47 | SOLVER.VAL_PERIOD 2000 \ 48 | SOLVER.CHECKPOINT_PERIOD 2000 \ 49 | OUTPUT_DIR $OUTPATH \ 50 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 51 | SOLVER.PRE_VAL False \ 52 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 53 | EM.MODE "x" \ 54 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON True \ 55 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 56 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 57 | GLOVE_DIR $GLOVE_DIR \ 58 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 59 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 60 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 61 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=1 4 | OUTPATH="checkpoints/50/motif/predcls/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | TEST.METRIC "R" \ 21 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 22 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 23 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 24 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 25 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 26 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 27 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 28 | OUTPUT_DIR $OUTPATH \ 29 | GLOVE_DIR $GLOVE_DIR 30 | else 31 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 32 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 33 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 34 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 35 | SOLVER.IMS_PER_BATCH 6 \ 36 | TEST.IMS_PER_BATCH 1 \ 37 | SOLVER.MAX_ITER 50000 \ 38 | SOLVER.VAL_PERIOD 2000 \ 39 | SOLVER.CHECKPOINT_PERIOD 2000 \ 40 | TEST.METRIC "R" \ 41 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 42 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.13 \ 43 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 1.6 \ 44 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 45 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 46 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 47 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 48 | OUTPUT_DIR $OUTPATH \ 49 | GLOVE_DIR $GLOVE_DIR 50 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/ie_trans/relabel/combine.sh: -------------------------------------------------------------------------------- 1 | OUTPATH="checkpoints/50/motif/predcls/ie_trans" 2 | mkdir -p $OUTPATH 3 | cp tools/ietrans/combine.py $OUTPATH 4 | cd $OUTPATH 5 | python combine.py 6 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/ie_trans/relabel/external.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" 2 | OUTPATH="checkpoints/50/motif/predcls/ie_trans" 3 | MODEL_WEIGHT_PATH="checkpoints/50/motif/predcls/ie_trans/pretrain/model_???.pth" # Insert the pretraiend model weight on predcls task 4 | GLOVE_DIR="Glove" # Glove directory 5 | 6 | mkdir -p $OUTPATH 7 | 8 | 9 | python tools/external_relabel.py --config-file "configs/wsup-50_external.yaml" \ 10 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 11 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 13 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 14 | SOLVER.IMS_PER_BATCH 6 TEST.IMS_PER_BATCH 1 \ 15 | SOLVER.MAX_ITER 50000 \ 16 | SOLVER.VAL_PERIOD 2000 \ 17 | SOLVER.CHECKPOINT_PERIOD 2000 \ 18 | OUTPUT_DIR $OUTPATH \ 19 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 20 | SOLVER.PRE_VAL False \ 21 | GLOVE_DIR $GLOVE_DIR \ 22 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON False \ 23 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 24 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 25 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.PRETRAIN_RELNESS_MODULE False \ 26 | WSUPERVISE.DATASET ExTransDataset EM.MODE E WSUPERVISE.SPECIFIED_DATA_FILE datasets_vg/vg/50/vg_clip_logits.pk 27 | 28 | 29 | cp tools/ietrans/external_cut.py $OUTPATH 30 | cp tools/ietrans/na_score_rank.py $OUTPATH 31 | cd $OUTPATH 32 | python na_score_rank.py 33 | python external_cut.py 1.0 # use all relabeled DS data 34 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/ie_trans/relabel/internal.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="6" 2 | OUTPATH="checkpoints/50/motif/predcls/ie_trans" # put the pre-trained model's path 3 | MODEL_WEIGHT_PATH="checkpoints/50/motif/predcls/ie_trans/pretrain/model_???.pth" # Insert the pretraiend model weight on predcls task 4 | 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | 8 | mkdir -p $OUTPATH 9 | 10 | python tools/internal_relabel.py --config-file "configs/wsup-50_internal.yaml" \ 11 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 15 | SOLVER.IMS_PER_BATCH 6 TEST.IMS_PER_BATCH 1 \ 16 | SOLVER.MAX_ITER 50000 \ 17 | SOLVER.VAL_PERIOD 2000 \ 18 | SOLVER.CHECKPOINT_PERIOD 2000 \ 19 | MODEL.PRETRAINED_DETECTOR_CKPT maskrcnn_benchmark/pretrained/pretrained_faster_rcnn/model_final.pth \ 20 | OUTPUT_DIR $OUTPATH \ 21 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 22 | SOLVER.PRE_VAL False \ 23 | GLOVE_DIR $GLOVE_DIR \ 24 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 25 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 26 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 27 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.SET_ON False \ 28 | MODEL.ROI_RELATION_HEAD.RELATION_PROPOSAL_MODEL.PRETRAIN_RELNESS_MODULE False \ 29 | WSUPERVISE.DATASET InTransDataset EM.MODE E WSUPERVISE.SPECIFIED_DATA_FILE datasets_vg/vg/50/vg_sup_data.pk 30 | 31 | 32 | 33 | cp tools/ietrans/internal_cut.py $OUTPATH 34 | cd $OUTPATH 35 | python internal_cut.py 0.7 36 | 37 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/ie_trans/relabel/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=1 4 | OUTPATH="checkpoints/50/motif/predcls/ie_trans/pretrain" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 15 | SOLVER.IMS_PER_BATCH 6 \ 16 | TEST.IMS_PER_BATCH 1 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | SOLVER.PRE_VAL False \ 21 | TEST.METRIC "R" \ 22 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 23 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 24 | OUTPUT_DIR $OUTPATH \ 25 | GLOVE_DIR $GLOVE_DIR \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 27 | else 28 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 29 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 30 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 31 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 32 | SOLVER.IMS_PER_BATCH 6 \ 33 | TEST.IMS_PER_BATCH 1 \ 34 | SOLVER.MAX_ITER 50000 \ 35 | SOLVER.VAL_PERIOD 2000 \ 36 | SOLVER.CHECKPOINT_PERIOD 2000 \ 37 | TEST.METRIC "R" \ 38 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 39 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 40 | SOLVER.PRE_VAL False \ 41 | OUTPUT_DIR $OUTPATH \ 42 | GLOVE_DIR $GLOVE_DIR \ 43 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 44 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=1 4 | 5 | OUTPATH="checkpoints/50/motif/predcls/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/motif/Motif_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | SOLVER.PRE_VAL False \ 28 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 29 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 30 | GLOVE_DIR $GLOVE_DIR \ 31 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 32 | EM.MODE "x" 33 | else 34 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 35 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 36 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 37 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 38 | SOLVER.IMS_PER_BATCH 6 \ 39 | TEST.IMS_PER_BATCH 1 \ 40 | SOLVER.MAX_ITER 50000 \ 41 | SOLVER.VAL_PERIOD 2000 \ 42 | SOLVER.CHECKPOINT_PERIOD 2000 \ 43 | OUTPUT_DIR $OUTPATH \ 44 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 45 | SOLVER.PRE_VAL False \ 46 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 47 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 48 | GLOVE_DIR $GLOVE_DIR \ 49 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 50 | EM.MODE "x" 51 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=1 4 | OUTPATH="checkpoints/50/motif/predcls/st_sgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | SPECIFIED_PATH="datasets/50/motif/Motif_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/motif/predcls/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | 11 | mkdir -p $OUTPATH 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 19 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 20 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 21 | SOLVER.IMS_PER_BATCH 12 \ 22 | TEST.IMS_PER_BATCH 2 \ 23 | SOLVER.MAX_ITER 50000 \ 24 | SOLVER.VAL_PERIOD 2000 \ 25 | SOLVER.CHECKPOINT_PERIOD 2000 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 28 | SOLVER.PRE_VAL False \ 29 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 30 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 33 | EM.MODE "x" \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 36 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 37 | else 38 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 39 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 41 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 42 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 43 | SOLVER.IMS_PER_BATCH 6 \ 44 | TEST.IMS_PER_BATCH 1 \ 45 | SOLVER.MAX_ITER 50000 \ 46 | SOLVER.VAL_PERIOD 2000 \ 47 | SOLVER.CHECKPOINT_PERIOD 2000 \ 48 | OUTPUT_DIR $OUTPATH \ 49 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 50 | SOLVER.PRE_VAL False \ 51 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 52 | MODEL.ROI_RELATION_HEAD.REL_OBJ_MULTI_TASK_LOSS False \ 53 | MODEL.ROI_RELATION_HEAD.OBJECT_CLASSIFICATION_REFINE False \ 54 | GLOVE_DIR $GLOVE_DIR \ 55 | EM.MODE "x" \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 57 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 58 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 59 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/vanilla/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=1 4 | OUTPATH="checkpoints/50/motif/predcls/base" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | mkdir -p $OUTPATH 8 | 9 | if $mutli_gpu;then 10 | python -m torch.distributed.launch \ 11 | --master_port 10093 --nproc_per_node=$num_gpu \ 12 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 14 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 15 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 16 | SOLVER.IMS_PER_BATCH 12 \ 17 | TEST.IMS_PER_BATCH 2 \ 18 | SOLVER.MAX_ITER 50000 \ 19 | SOLVER.VAL_PERIOD 2000 \ 20 | SOLVER.CHECKPOINT_PERIOD 2000 \ 21 | SOLVER.PRE_VAL False \ 22 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 23 | TEST.METRIC "R" \ 24 | OUTPUT_DIR $OUTPATH \ 25 | GLOVE_DIR $GLOVE_DIR \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 27 | else 28 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 29 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 30 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 31 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 32 | SOLVER.IMS_PER_BATCH 6 \ 33 | TEST.IMS_PER_BATCH 1 \ 34 | SOLVER.MAX_ITER 50000 \ 35 | SOLVER.VAL_PERIOD 2000 \ 36 | SOLVER.CHECKPOINT_PERIOD 2000 \ 37 | TEST.METRIC "R" \ 38 | SOLVER.PRE_VAL False \ 39 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 40 | OUTPUT_DIR $OUTPATH \ 41 | GLOVE_DIR $GLOVE_DIR \ 42 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 43 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/predcls/vanilla/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=1 4 | OUTPATH="checkpoints/50/motif/predcls/base_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | #ST-SGG Hyper-parameter 8 | ALPHA_DEC=0.4 9 | ALPHA_INC=0.8 10 | PRETRAINED_WEIGHT_PATH="checkpoints/50/motif/predcls/base/model_???.pth" # Path of pretrained model 11 | mkdir -p $OUTPATH 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 19 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 20 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 21 | SOLVER.IMS_PER_BATCH 12 \ 22 | TEST.IMS_PER_BATCH 2 \ 23 | SOLVER.MAX_ITER 50000 \ 24 | SOLVER.VAL_PERIOD 2000 \ 25 | SOLVER.CHECKPOINT_PERIOD 2000 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 28 | SOLVER.PRE_VAL False \ 29 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 30 | TEST.INFERENCE "SOFTMAX" \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 36 | else 37 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 38 | DATASETS.TRAIN \(\"50DS_VG_VGKB_train\",\) \ 39 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL True \ 41 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 42 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 43 | SOLVER.IMS_PER_BATCH 6 \ 44 | TEST.IMS_PER_BATCH 1 \ 45 | SOLVER.MAX_ITER 50000 \ 46 | SOLVER.VAL_PERIOD 2000 \ 47 | SOLVER.CHECKPOINT_PERIOD 2000 \ 48 | OUTPUT_DIR $OUTPATH \ 49 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 50 | SOLVER.PRE_VAL False \ 51 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 52 | TEST.INFERENCE "SOFTMAX" \ 53 | GLOVE_DIR $GLOVE_DIR \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 55 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 57 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 58 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgcls/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="1" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgcls/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | SOLVER.PRE_VAL False \ 21 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 22 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 23 | TEST.METRIC "R" \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 27 | OUTPUT_DIR $OUTPATH \ 28 | GLOVE_DIR $GLOVE_DIR 29 | else 30 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 31 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 32 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 33 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 34 | SOLVER.IMS_PER_BATCH 6 \ 35 | TEST.IMS_PER_BATCH 1 \ 36 | SOLVER.MAX_ITER 50000 \ 37 | SOLVER.VAL_PERIOD 2000 \ 38 | SOLVER.CHECKPOINT_PERIOD 2000 \ 39 | TEST.METRIC "R" \ 40 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 41 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 42 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 43 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 44 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 45 | SOLVER.PRE_VAL False \ 46 | OUTPUT_DIR $OUTPATH \ 47 | GLOVE_DIR $GLOVE_DIR 48 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgcls/bilvl/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgcls/bilvl_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | ALPHA_DEC=0.4 7 | ALPHA_INC=0.4 8 | MODEL_WEIGHT_PATH="checkpoints/50/motif/sgcls/bilvl/model_???.pth" # Path of pretrained model 9 | mkdir -p $OUTPATH 10 | 11 | if $mutli_gpu;then 12 | python -m torch.distributed.launch \ 13 | --master_port 10093 --nproc_per_node=$num_gpu \ 14 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 15 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 17 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 18 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 19 | SOLVER.IMS_PER_BATCH 12 \ 20 | TEST.IMS_PER_BATCH 2 \ 21 | SOLVER.MAX_ITER 50000 \ 22 | SOLVER.VAL_PERIOD 2000 \ 23 | SOLVER.CHECKPOINT_PERIOD 2000 \ 24 | OUTPUT_DIR $OUTPATH \ 25 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 26 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 27 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 28 | GLOVE_DIR $GLOVE_DIR \ 29 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 30 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 31 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 35 | else 36 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 39 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 40 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 41 | SOLVER.IMS_PER_BATCH 6 \ 42 | TEST.IMS_PER_BATCH 1 \ 43 | SOLVER.MAX_ITER 50000 \ 44 | SOLVER.VAL_PERIOD 2000 \ 45 | SOLVER.CHECKPOINT_PERIOD 2000 \ 46 | OUTPUT_DIR $OUTPATH \ 47 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 48 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 49 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 50 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 51 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 52 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 53 | GLOVE_DIR $GLOVE_DIR \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 55 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 57 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgcls/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/motif/sgcls/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/motif/Motif_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | GLOVE_DIR $GLOVE_DIR \ 28 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 29 | WSUPERVISE.DATASET InTransDataset \ 30 | EM.MODE "x" 31 | else 32 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 33 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 34 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 35 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 36 | SOLVER.IMS_PER_BATCH 6 \ 37 | TEST.IMS_PER_BATCH 1 \ 38 | SOLVER.MAX_ITER 50000 \ 39 | SOLVER.VAL_PERIOD 2000 \ 40 | SOLVER.CHECKPOINT_PERIOD 2000 \ 41 | OUTPUT_DIR $OUTPATH \ 42 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 43 | GLOVE_DIR $GLOVE_DIR \ 44 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 45 | EM.MODE "x" 46 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgcls/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgcls/st_sgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | SPECIFIED_PATH="datasets/50/motif/Motif_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/motif/sgcls/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | mkdir -p $OUTPATH 11 | 12 | if $mutli_gpu;then 13 | python -m torch.distributed.launch \ 14 | --master_port 10093 --nproc_per_node=$num_gpu \ 15 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 18 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 28 | EM.MODE "x" \ 29 | GLOVE_DIR $GLOVE_DIR \ 30 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 31 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 33 | else 34 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 35 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 36 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 37 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 38 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 39 | SOLVER.IMS_PER_BATCH 6 \ 40 | TEST.IMS_PER_BATCH 1 \ 41 | SOLVER.MAX_ITER 50000 \ 42 | SOLVER.VAL_PERIOD 2000 \ 43 | SOLVER.CHECKPOINT_PERIOD 2000 \ 44 | OUTPUT_DIR $OUTPATH \ 45 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 46 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 47 | EM.MODE "x" \ 48 | GLOVE_DIR $GLOVE_DIR \ 49 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 50 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 51 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 52 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgcls/vanilla/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgcls/base" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | mkdir -p $OUTPATH 8 | 9 | if $mutli_gpu;then 10 | python -m torch.distributed.launch \ 11 | --master_port 10093 --nproc_per_node=$num_gpu \ 12 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 14 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 15 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 16 | SOLVER.IMS_PER_BATCH 12 \ 17 | TEST.IMS_PER_BATCH 2 \ 18 | SOLVER.MAX_ITER 50000 \ 19 | SOLVER.VAL_PERIOD 2000 \ 20 | SOLVER.CHECKPOINT_PERIOD 2000 \ 21 | SOLVER.PRE_VAL False \ 22 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 23 | TEST.METRIC "R" \ 24 | OUTPUT_DIR $OUTPATH \ 25 | GLOVE_DIR $GLOVE_DIR \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 27 | else 28 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 29 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 30 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 31 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 32 | SOLVER.IMS_PER_BATCH 6 \ 33 | TEST.IMS_PER_BATCH 1 \ 34 | SOLVER.MAX_ITER 50000 \ 35 | SOLVER.VAL_PERIOD 2000 \ 36 | SOLVER.CHECKPOINT_PERIOD 2000 \ 37 | TEST.METRIC "R" \ 38 | SOLVER.PRE_VAL False \ 39 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 40 | OUTPUT_DIR $OUTPATH \ 41 | GLOVE_DIR $GLOVE_DIR \ 42 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 43 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgcls/vanilla/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgcls/base_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | #ST-SGG Hyper-parameter 8 | ALPHA_DEC=0.4 9 | ALPHA_INC=0.8 10 | PRETRAINED_WEIGHT_PATH="checkpoints/50/motif/sgcls/base/model_???.pth" # Path of pretrained model 11 | mkdir -p $OUTPATH 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 20 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 21 | SOLVER.IMS_PER_BATCH 12 \ 22 | TEST.IMS_PER_BATCH 2 \ 23 | SOLVER.MAX_ITER 50000 \ 24 | SOLVER.VAL_PERIOD 2000 \ 25 | SOLVER.CHECKPOINT_PERIOD 2000 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 28 | SOLVER.PRE_VAL False \ 29 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 30 | TEST.INFERENCE "SOFTMAX" \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 36 | else 37 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 38 | DATASETS.TRAIN \(\"50DS_VG_VGKB_train\",\) \ 39 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX True \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 41 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 42 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 43 | SOLVER.IMS_PER_BATCH 6 \ 44 | TEST.IMS_PER_BATCH 1 \ 45 | SOLVER.MAX_ITER 50000 \ 46 | SOLVER.VAL_PERIOD 2000 \ 47 | SOLVER.CHECKPOINT_PERIOD 2000 \ 48 | OUTPUT_DIR $OUTPATH \ 49 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 50 | SOLVER.PRE_VAL False \ 51 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 52 | TEST.INFERENCE "SOFTMAX" \ 53 | GLOVE_DIR $GLOVE_DIR \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 55 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 57 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 58 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgdet/bilvl/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgdet/bilvl" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | mkdir -p $OUTPATH 7 | 8 | if $mutli_gpu;then 9 | python -m torch.distributed.launch \ 10 | --master_port 10093 --nproc_per_node=$num_gpu \ 11 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 12 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 14 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 15 | SOLVER.IMS_PER_BATCH 12 \ 16 | TEST.IMS_PER_BATCH 2 \ 17 | SOLVER.MAX_ITER 50000 \ 18 | SOLVER.VAL_PERIOD 2000 \ 19 | SOLVER.CHECKPOINT_PERIOD 2000 \ 20 | TEST.METRIC "R" \ 21 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 22 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 23 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 24 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 25 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | GLOVE_DIR $GLOVE_DIR 28 | else 29 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 30 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 31 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 32 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 33 | SOLVER.IMS_PER_BATCH 6 \ 34 | TEST.IMS_PER_BATCH 1 \ 35 | SOLVER.MAX_ITER 50000 \ 36 | SOLVER.VAL_PERIOD 2000 \ 37 | SOLVER.CHECKPOINT_PERIOD 2000 \ 38 | TEST.METRIC "R" \ 39 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 40 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 41 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 42 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 43 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 44 | OUTPUT_DIR $OUTPATH \ 45 | GLOVE_DIR $GLOVE_DIR 46 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgdet/bilvl/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgdet/bilvl_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | ALPHA_DEC=0.4 7 | ALPHA_INC=0.4 8 | MODEL_WEIGHT_PATH="checkpoints/50/motif/sgdet/bilvl/model_???.pth" # Path of pretrained model 9 | mkdir -p $OUTPATH 10 | 11 | if $mutli_gpu;then 12 | python -m torch.distributed.launch \ 13 | --master_port 10093 --nproc_per_node=$num_gpu \ 14 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 15 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 17 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 18 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 19 | SOLVER.IMS_PER_BATCH 12 \ 20 | TEST.IMS_PER_BATCH 2 \ 21 | SOLVER.MAX_ITER 50000 \ 22 | SOLVER.VAL_PERIOD 2000 \ 23 | SOLVER.CHECKPOINT_PERIOD 2000 \ 24 | OUTPUT_DIR $OUTPATH \ 25 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 26 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 27 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 28 | GLOVE_DIR $GLOVE_DIR \ 29 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 30 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 31 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 35 | else 36 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 39 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 40 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 41 | SOLVER.IMS_PER_BATCH 6 \ 42 | TEST.IMS_PER_BATCH 1 \ 43 | SOLVER.MAX_ITER 50000 \ 44 | SOLVER.VAL_PERIOD 2000 \ 45 | SOLVER.CHECKPOINT_PERIOD 2000 \ 46 | OUTPUT_DIR $OUTPATH \ 47 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 48 | MODEL.ROI_RELATION_HEAD.TRAIN_USE_BIAS True \ 49 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 50 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING True \ 51 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.REPEAT_FACTOR 0.1 \ 52 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING_PARAM.INSTANCE_DROP_RATE 0.9 \ 53 | GLOVE_DIR $GLOVE_DIR \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 55 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 57 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgdet/ie_trans/train.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | 5 | OUTPATH="checkpoints/50/motif/sgdet/no_ext_yes_int" 6 | SPECIFIED_PATH="datasets/50/motif/Motif_i-trans.pk" 7 | GLOVE_DIR="Glove" # Glove directory 8 | 9 | mkdir -p $OUTPATH 10 | # cp $EXP/50/motif/predcls/lt/combine/relabel/em_E.pk $OUTPATH/em_E.pk 11 | 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | SOLVER.PRE_VAL False \ 28 | GLOVE_DIR $GLOVE_DIR \ 29 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 30 | MODEL.PRETRAINED_DETECTOR_CKPT $DETECTOR_DIR \ 31 | EM.MODE "x" 32 | else 33 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 34 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 35 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 36 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 37 | SOLVER.IMS_PER_BATCH 6 \ 38 | TEST.IMS_PER_BATCH 1 \ 39 | SOLVER.MAX_ITER 50000 \ 40 | SOLVER.VAL_PERIOD 2000 \ 41 | SOLVER.CHECKPOINT_PERIOD 2000 \ 42 | OUTPUT_DIR $OUTPATH \ 43 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 44 | SOLVER.PRE_VAL False \ 45 | GLOVE_DIR $GLOVE_DIR \ 46 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 47 | EM.MODE "x" 48 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgdet/ie_trans/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgdet/st_sgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | SPECIFIED_PATH="datasets/50/motif/Motif_i-trans.pk" 7 | ALPHA_DEC=0.4 8 | ALPHA_INC=0.4 9 | MODEL_WEIGHT_PATH="checkpoints/50/motif/sgdet/no_ext_yes_int/model_???.pth" # Path of pretrained model 10 | mkdir -p $OUTPATH 11 | 12 | if $mutli_gpu;then 13 | python -m torch.distributed.launch \ 14 | --master_port 10093 --nproc_per_node=$num_gpu \ 15 | tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 16 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 18 | MODEL.WEIGHT $MODEL_WEIGHT_PATH \ 19 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 20 | SOLVER.IMS_PER_BATCH 12 \ 21 | TEST.IMS_PER_BATCH 2 \ 22 | SOLVER.MAX_ITER 50000 \ 23 | SOLVER.VAL_PERIOD 2000 \ 24 | SOLVER.CHECKPOINT_PERIOD 2000 \ 25 | OUTPUT_DIR $OUTPATH \ 26 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 27 | SOLVER.PRE_VAL False \ 28 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 29 | WSUPERVISE.DATASET InTransDataset \ 30 | EM.MODE "x" \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 35 | else 36 | python tools/relation_train_net.py --config-file "configs/wsup-50.yaml" \ 37 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 38 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 39 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 40 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 41 | SOLVER.IMS_PER_BATCH 6 \ 42 | TEST.IMS_PER_BATCH 1 \ 43 | SOLVER.MAX_ITER 50000 \ 44 | SOLVER.VAL_PERIOD 2000 \ 45 | SOLVER.CHECKPOINT_PERIOD 2000 \ 46 | OUTPUT_DIR $OUTPATH \ 47 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 48 | SOLVER.PRE_VAL False \ 49 | WSUPERVISE.SPECIFIED_DATA_FILE $SPECIFIED_PATH \ 50 | EM.MODE "x" \ 51 | GLOVE_DIR $GLOVE_DIR \ 52 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 53 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 55 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgdet/vanilla/pretrain.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgdet/base" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | mkdir -p $OUTPATH 8 | 9 | if $mutli_gpu;then 10 | python -m torch.distributed.launch \ 11 | --master_port 10093 --nproc_per_node=$num_gpu \ 12 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 13 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 14 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 15 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 16 | SOLVER.IMS_PER_BATCH 12 \ 17 | TEST.IMS_PER_BATCH 2 \ 18 | SOLVER.MAX_ITER 50000 \ 19 | SOLVER.VAL_PERIOD 2000 \ 20 | SOLVER.CHECKPOINT_PERIOD 2000 \ 21 | SOLVER.PRE_VAL False \ 22 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 23 | TEST.METRIC "R" \ 24 | OUTPUT_DIR $OUTPATH \ 25 | GLOVE_DIR $GLOVE_DIR \ 26 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 27 | else 28 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 29 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 30 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 31 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor \ 32 | SOLVER.IMS_PER_BATCH 6 \ 33 | TEST.IMS_PER_BATCH 1 \ 34 | SOLVER.MAX_ITER 50000 \ 35 | SOLVER.VAL_PERIOD 2000 \ 36 | SOLVER.CHECKPOINT_PERIOD 2000 \ 37 | TEST.METRIC "R" \ 38 | SOLVER.PRE_VAL False \ 39 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 40 | OUTPUT_DIR $OUTPATH \ 41 | GLOVE_DIR $GLOVE_DIR \ 42 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False 43 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/run_shell/motif/sgdet/vanilla/train_stsgg.sh: -------------------------------------------------------------------------------- 1 | export CUDA_VISIBLE_DEVICES="0" # if you use multi-gpu, then insert the number of gpu e.g., export CUDA_VISIBLE_DEVICES="4,5" 2 | mutli_gpu=false # whether use multi-gpu or not 3 | num_gpu=2 4 | OUTPATH="checkpoints/50/motif/sgdet/base_stsgg" # save directory 5 | GLOVE_DIR="Glove" # Glove directory 6 | 7 | #ST-SGG Hyper-parameter 8 | ALPHA_DEC=0.4 9 | ALPHA_INC=0.8 10 | PRETRAINED_WEIGHT_PATH="checkpoints/50/motif/sgdet/base/model_???.pth" # Path of pretrained model 11 | mkdir -p $OUTPATH 12 | 13 | if $mutli_gpu;then 14 | python -m torch.distributed.launch \ 15 | --master_port 10093 --nproc_per_node=$num_gpu \ 16 | tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 17 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 18 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 19 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 20 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 21 | SOLVER.IMS_PER_BATCH 12 \ 22 | TEST.IMS_PER_BATCH 2 \ 23 | SOLVER.MAX_ITER 50000 \ 24 | SOLVER.VAL_PERIOD 2000 \ 25 | SOLVER.CHECKPOINT_PERIOD 2000 \ 26 | OUTPUT_DIR $OUTPATH \ 27 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 28 | SOLVER.PRE_VAL False \ 29 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 30 | TEST.INFERENCE "SOFTMAX" \ 31 | GLOVE_DIR $GLOVE_DIR \ 32 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 33 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False \ 34 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 35 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 36 | else 37 | python tools/relation_train_net.py --config-file "configs/sup-50.yaml" \ 38 | DATASETS.TRAIN \(\"50DS_VG_VGKB_train\",\) \ 39 | MODEL.ROI_RELATION_HEAD.USE_GT_BOX False \ 40 | MODEL.ROI_RELATION_HEAD.USE_GT_OBJECT_LABEL False \ 41 | MODEL.WEIGHT $PRETRAINED_WEIGHT_PATH \ 42 | MODEL.ROI_RELATION_HEAD.PREDICTOR MotifPredictor_STSGG \ 43 | SOLVER.IMS_PER_BATCH 6 \ 44 | TEST.IMS_PER_BATCH 1 \ 45 | SOLVER.MAX_ITER 50000 \ 46 | SOLVER.VAL_PERIOD 2000 \ 47 | SOLVER.CHECKPOINT_PERIOD 2000 \ 48 | OUTPUT_DIR $OUTPATH \ 49 | MODEL.ROI_RELATION_HEAD.NUM_CLASSES 51 \ 50 | SOLVER.PRE_VAL False \ 51 | MODEL.ROI_RELATION_HEAD.PREDICT_USE_BIAS True \ 52 | TEST.INFERENCE "SOFTMAX" \ 53 | GLOVE_DIR $GLOVE_DIR \ 54 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.BETA 1.0 \ 55 | MODEL.ROI_RELATION_HEAD.DATA_RESAMPLING False \ 56 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_DEC $ALPHA_DEC \ 57 | MODEL.ROI_RELATION_HEAD.STSGG_MODULE.ALPHA_INC $ALPHA_INC 58 | fi -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/setup.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. 2 | #!/usr/bin/env python 3 | 4 | import glob 5 | import os 6 | 7 | import torch 8 | from setuptools import find_packages 9 | from setuptools import setup 10 | from torch.utils.cpp_extension import CUDA_HOME 11 | from torch.utils.cpp_extension import CppExtension 12 | from torch.utils.cpp_extension import CUDAExtension 13 | 14 | requirements = ["torch", "torchvision"] 15 | 16 | 17 | def get_extensions(): 18 | this_dir = os.path.dirname(os.path.abspath(__file__)) 19 | extensions_dir = os.path.join(this_dir, "maskrcnn_benchmark", "csrc") 20 | 21 | main_file = glob.glob(os.path.join(extensions_dir, "*.cpp")) 22 | source_cpu = glob.glob(os.path.join(extensions_dir, "cpu", "*.cpp")) 23 | source_cuda = glob.glob(os.path.join(extensions_dir, "cuda", "*.cu")) 24 | 25 | sources = main_file + source_cpu 26 | extension = CppExtension 27 | 28 | extra_compile_args = {"cxx": []} 29 | define_macros = [] 30 | 31 | if (torch.cuda.is_available() and CUDA_HOME is not None) or os.getenv("FORCE_CUDA", "0") == "1": 32 | extension = CUDAExtension 33 | sources += source_cuda 34 | define_macros += [("WITH_CUDA", None)] 35 | extra_compile_args["nvcc"] = [ 36 | "-DCUDA_HAS_FP16=1", 37 | "-D__CUDA_NO_HALF_OPERATORS__", 38 | "-D__CUDA_NO_HALF_CONVERSIONS__", 39 | "-D__CUDA_NO_HALF2_OPERATORS__", 40 | ] 41 | 42 | sources = [os.path.join(extensions_dir, s) for s in sources] 43 | 44 | include_dirs = [extensions_dir] 45 | 46 | ext_modules = [ 47 | extension( 48 | "maskrcnn_benchmark._C", 49 | sources, 50 | include_dirs=include_dirs, 51 | define_macros=define_macros, 52 | extra_compile_args=extra_compile_args, 53 | ) 54 | ] 55 | 56 | return ext_modules 57 | 58 | 59 | setup( 60 | name="maskrcnn_benchmark", 61 | version="0.1", 62 | author="fmassa", 63 | url="https://github.com/facebookresearch/maskrcnn-benchmark", 64 | description="object detection in pytorch", 65 | packages=find_packages(exclude=("configs", "tests", )), 66 | # install_requires=requirements, 67 | ext_modules=get_extensions(), 68 | cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension}, 69 | ) 70 | -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/tools/ietrans/external_cut.py: -------------------------------------------------------------------------------- 1 | import json 2 | import pickle 3 | import numpy as np 4 | import os 5 | import torch 6 | ratio = 1.0 7 | print(ratio) 8 | score = json.load(open("External/score.json", "r")) 9 | em = pickle.load(open("External/raw_em_E.pk", "rb")) 10 | if ratio == 1.0: 11 | thres = score[-1] 12 | elif ratio == 0.0: 13 | thres = score[0] 14 | else: 15 | thres = score[int(ratio * len(score))-1] 16 | 17 | n = 0 18 | rst = [] 19 | for d in em: 20 | pairs = d['pairs'] 21 | rel_logits = d['rel_logits'] 22 | possible_rels = d['possible_rels'] 23 | rst_pairs = [] 24 | rst_rel_logits = [] 25 | rst_possible_rels = [] 26 | for i, (logit, rels) in enumerate(zip(rel_logits, possible_rels)): 27 | s = torch.tensor(logit).softmax(0)[-1] 28 | if s > thres: 29 | # do not transfer 30 | # rst_pairs.append(pairs[i]) 31 | 32 | continue 33 | else: 34 | # transfer 35 | rst_pairs.append(pairs[i]) 36 | rst_rel_logits.append(logit[0:-1]) 37 | rst_possible_rels.append(rels[:-1]) 38 | d['pairs'] = np.asarray(rst_pairs) 39 | d['rel_logits'] = rst_rel_logits 40 | d['possible_rels'] = rst_possible_rels 41 | if rst_rel_logits == []: 42 | n += 1 43 | rst.append(None) 44 | else: 45 | rst.append(d) 46 | # pickle.dump(rst, open("em_E.pk"+str(round(ratio, 2)), "wb")) 47 | os.makedirs("External", exist_ok=True) 48 | pickle.dump(rst, open(f"External/External_{ratio}.pk", "wb")) 49 | print(n) -------------------------------------------------------------------------------- /Self-Training Framework for Scene Graph Generation/tools/ietrans/na_score_rank.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | sys.path.append(os.getcwd()) 4 | import torch 5 | 6 | import json 7 | import pickle 8 | l = pickle.load(open("External/raw_em_E.pk", "rb")) 9 | 10 | def score(): 11 | rst = [] 12 | correct = 0 13 | n = 0 14 | for d in l: 15 | logits = d['rel_logits'] 16 | for lg in logits: 17 | rst.append(torch.tensor(lg).softmax(0)[-1].item()) 18 | return rst 19 | 20 | rst = score() 21 | rst = sorted(rst) 22 | json.dump(rst, open("External/score.json", "w")) 23 | 24 | --------------------------------------------------------------------------------