{"id":19010871,"url":"https://github.com/yinboc/dgp","last_synced_at":"2025-04-09T21:19:10.069Z","repository":{"id":112530652,"uuid":"135530747","full_name":"yinboc/DGP","owner":"yinboc","description":"Rethinking Knowledge Graph Propagation for Zero-Shot Learning, in CVPR 2019","archived":false,"fork":false,"pushed_at":"2019-06-22T08:53:59.000Z","size":455,"stargazers_count":318,"open_issues_count":1,"forks_count":57,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-09T21:19:03.965Z","etag":null,"topics":["knowledge-graph","machine-learning","pytorch","zero-shot-learning"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yinboc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-05-31T04:17:03.000Z","updated_at":"2025-04-03T02:21:59.000Z","dependencies_parsed_at":"2023-05-15T17:30:36.413Z","dependency_job_id":null,"html_url":"https://github.com/yinboc/DGP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinboc%2FDGP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinboc%2FDGP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinboc%2FDGP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yinboc%2FDGP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yinboc","download_url":"https://codeload.github.com/yinboc/DGP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111973,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["knowledge-graph","machine-learning","pytorch","zero-shot-learning"],"created_at":"2024-11-08T19:12:44.388Z","updated_at":"2025-04-09T21:19:10.041Z","avatar_url":"https://github.com/yinboc.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dense Graph Propagation\n\nThe code for the paper [Rethinking Knowledge Graph Propagation for Zero-Shot Learning](https://arxiv.org/abs/1805.11724).\n\n### Citation\n```\n@inproceedings{kampffmeyer2019rethinking,\n  title={Rethinking knowledge graph propagation for zero-shot learning},\n  author={Kampffmeyer, Michael and Chen, Yinbo and Liang, Xiaodan and Wang, Hao and Zhang, Yujia and Xing, Eric P},\n  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},\n  pages={11487--11496},\n  year={2019}\n}\n```\n\n## Requirements\n\n* python 3\n* pytorch 0.4.0\n* nltk\n\n## Instructions\n\n### Materials Preparation\n\nThere is a folder `materials/`, which contains some meta data and programs already.\n\n#### Glove Word Embedding\n1. Download: http://nlp.stanford.edu/data/glove.6B.zip\n2. Unzip it, find and put `glove.6B.300d.txt` to `materials/`.\n\n#### Graphs\n1. `cd materials/`\n2. Run `python make_induced_graph.py`, get `imagenet-induced-graph.json`\n3. Run `python make_dense_graph.py`, get `imagenet-dense-graph.json`\n3. Run `python make_dense_grouped_graph.py`, get `imagenet-dense-grouped-graph.json`\n\n#### Pretrained ResNet50\n1. Download: https://download.pytorch.org/models/resnet50-19c8e357.pth\n2. Rename and put it as `materials/resnet50-raw.pth`\n3. `cd materials/`, run `python process_resnet.py`, get `fc-weights.json` and `resnet50-base.pth`\n\n#### ImageNet and AwA2\n\nDownload ImageNet and AwA2, create the softlinks (command `ln -s`): `materials/datasets/imagenet` and `materials/datasets/awa2`, to the root directory of the dataset.\n\nAn ImageNet root directory should contain image folders, each folder with the wordnet id of the class.\n\nAn AwA2 root directory should contain the folder JPEGImages.\n\n### Training\n\nMake a directory `save/` for saving models.\n\nIn most programs, use `--gpu` to specify the devices to run the code (default: use gpu 0).\n\n#### Train Graph Networks\n* SGCN: Run `python train_gcn_basic.py`, get results in `save/gcn-basic`\n* DGP: Run `python train_gcn_dense_att.py`, get results in `save/gcn-dense-att`\n\nIn the results folder:\n* `*.pth` is the state dict of Graph Networks model\n* `*.pred` is the prediction file, which can be loaded by `torch.load()`. It is a python dict, having two keys: `wnids` - the wordnet ids of the predicted classes, `pred` - the predicted fc weights\n\n#### Finetune ResNet\nRun `python train_resnet_fit.py` with the args:\n* `--pred`: the `.pred` file for finetuning\n* `--train-dir`: the directory contains 1K imagenet training classes, each class with a folder named by its wordnet id\n* `--save-path`: the folder you want to save the result, e.g. `save/resnet-fit-xxx`\n\n(In the paper's setting, --train-dir is the folder composed of 1K classes from fall2011.tar, with the missing class \"teddy bear\" from ILSVRC2012.)\n\n### Testing\n\n#### ImageNet\nRun `python evaluate_imagenet.py` with the args:\n* `--cnn`: path to resnet50 weights, e.g. `materials/resnet50-base.pth` or `save/resnet-fit-xxx/x.pth`\n* `--pred`: the `.pred` file for testing\n* `--test-set`: load test set in `materials/imagenet-testsets.json`, choices: `[2-hops, 3-hops, all]`\n* (optional) `--keep-ratio` for the ratio of testing data, `--consider-trains` to include training classes' classifiers, `--test-train` for testing with train classes images only.\n\n#### AwA2\nRun `python evaluate_awa2.py` with the args:\n* `--cnn`: path to resnet50 weights, e.g. `materials/resnet50-base.pth` or `save/resnet-fit-xxx/x.pth`\n* `--pred`: the `.pred` file for testing\n* (optional) `--consider-trains` to include training classes' classifiers\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyinboc%2Fdgp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyinboc%2Fdgp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyinboc%2Fdgp/lists"}