File size: 2,300 Bytes
e19eae7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
license: mit
library_name: pytorch
datasets:
  - structlearning/isonetpp-benchmark
tags:
  - graphs
  - subgraph-matching
  - graph-retrieval
task_categories:
  - graph-ml
---


    # ISONeT++ Model: simgnn on ptc_mr

    Trained on the **large** split.

    ## Usage

    ```python
    import torch
    import json
    from utils.tooling import make_read_only
    from subgraph_matching.model_handler import get_model
    from subgraph_matching.test import evaluate_model

    
    from huggingface_hub import hf_hub_download

    model_name = "simgnn"
    dataset_name = "ptc_mr"
    
    REPO_ID = "structlearning/isonetpp-benchmark"  # change if you fork/rename

    def _load_module_from_hub(repo_id, filename, repo_type="dataset", module_name=None):
        path = hf_hub_download(repo_id=repo_id, filename=filename, repo_type=repo_type)
        name = module_name or filename.rsplit(".", 1)[0]
        spec = importlib.util.spec_from_file_location(name, path)
        mod = importlib.util.module_from_spec(spec)
        sys.modules[name] = mod
        spec.loader.exec_module(mod)
        return mod

    dataset_mod = _load_module_from_hub(REPO_ID, "subiso_dataset.py", repo_type="dataset", module_name="subiso_dataset")
    loader = _load_module_from_hub(REPO_ID, "isonetpp_loader.py", repo_type="dataset", module_name="isonetpp_loader")


    ds_test = loader.load_isonetpp_benchmark(
        repo_id=REPO_ID,
        mode="test",           # "train" | "val" | "test"
        dataset_name="ptc_mr"
    )

    repo_id = f"structlearning/isonetpp-simgnn-ptc_mr-large"

    # Load config
    config = json.load(open(hf_hub_download(repo_id, "config.json")))
    config = make_read_only(config)

    # Load weights
    weights = hf_hub_download(repo_id, "pytorch_model.bin")
    state = torch.load(weights,  weights_only=False)

    # Load dataset
    ds_test = loader.load_isonetpp_benchmark(dataset_name="ptc_mr", mode="test")

    model = get_model(
        model_name=config.name,
        config=config.model_config,
        max_node_set_size=ds_test.max_node_set_size,
        max_edge_set_size=ds_test.max_edge_set_size,
        device="cuda"
    )
    model.load_state_dict(state)
    model.to("cuda")

    _, map_val = evaluate_model(model, ds_test)
    print(map_val)

    ```