Code for paper 'Knowledge Enhanced Zero-shot Visual Relationship Detection'.
The model comprises two modules: logic tensor networks encoded negative domain of semantic and spatial knowledge, and a commonsense knowledge graph module updated by local spatial structure as positive domain semantic knowledge. Predictions are further constrained by region connection calculus (RCC).
- The
modelsfolder contains the trained grounded theories of the experiments; - The
Visual-Relationship-Detection-masterfolder contains the object detector model and the evaluation code provided in https://github.com/Prof-Lu-Cewu/Visual-Relationship-Detection for the evaluation of the phrase, relationship and predicate detection tasks on the VRD. - The
datafolder contains the data which can be downloaded from https://cs.stanford.edu/people/ranjaykrishna/vrd/ - The ConceptNet can be downloaded from https://github.com/commonsense/conceptnet-numberbatch
The packages needed in training can be downloaded following :
pip install -r requirements.txt
Use the complete model:
$ python train_all.pyUse LTNs :
$ python train.pyUse without spatial knowledge :
$ python train_mul.pyUse without CKG module :
$ python train_RCC.py- The trained models are saved in the
modelsfolder in the filesKB_wc_2500.ckpt(with constraints). The number in the filename (2500) is a parameter in the code to set the number of iterations.
To run the evaluation use the following commands
$ python predicate_detection_mul.py$ python relationship_phrase_detection_mul.pyThen, launch Matlab, move into the Visual-Relationship-Detection-master folder, execute the scripts predicate_detection_LTN.m and relationship_phrase_detection_LTN.m and see the results.
This repository is based on our references [3] and [5]
[3] Chen, J., He, H., Wu, F., Wang, J.: Topology-aware correlations between relations for inductive link prediction in knowledge graphs. In: AAAI. vol. 35, pp. 6271–6278 (2021)
[5] Donadello, I., Serafini, L.: Compensating supervision incompleteness with prior knowledge in semantic image interpretation. In: IJCNN. pp. 1–8. IEEE (2019).