Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,116 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: apache-2.0
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- graph-neural-networks
|
| 5 |
+
- histopathology
|
| 6 |
+
- self-supervised-learning
|
| 7 |
+
- pytorch-geometric
|
| 8 |
+
- graph-representation-learning
|
| 9 |
+
datasets:
|
| 10 |
+
- graph-tcga-brca
|
| 11 |
+
library_name: pytorch
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# GrapHist: Graph Self-Supervised Learning for Histopathology
|
| 15 |
+
|
| 16 |
+
This repository contains the pre-trained model from [GrapHist](https://github.com/ogutsevda/graphist). Pre-trained on the [graph-tcga-brca](https://huggingface.co/datasets/ogutsevda/graph-tcga-brca) dataset, it employs an **ACM-GIN** (Adaptive Channel Mixing Graph Isomorphism Network) encoder-decoder architecture with a masked node attribute prediction objective.
|
| 17 |
+
|
| 18 |
+
<p align="center">
|
| 19 |
+
<img src="graphist.png" alt="GrapHist architecture" width="100%">
|
| 20 |
+
</p>
|
| 21 |
+
|
| 22 |
+
## Repository Structure
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
graphist/
|
| 26 |
+
βββ graphist.pt # Pre-trained model checkpoint
|
| 27 |
+
βββ graphist.png # Architecture overview
|
| 28 |
+
βββ models/
|
| 29 |
+
β βββ __init__.py # build_model(args) factory
|
| 30 |
+
β βββ edcoder.py # PreModel encoder-decoder wrapper
|
| 31 |
+
β βββ acm_gin.py # ACM-GIN backbone (encoder/decoder)
|
| 32 |
+
β βββ utils.py # Activation and normalization helpers
|
| 33 |
+
βββ README.md
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
## Requirements
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
torch
|
| 40 |
+
torch-geometric
|
| 41 |
+
huggingface_hub
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
The model expects graphs in PyTorch Geometric format with `x`, `edge_index`, `edge_attr`, and `batch`.
|
| 45 |
+
|
| 46 |
+
## Usage
|
| 47 |
+
|
| 48 |
+
### 1. Clone the repository
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from huggingface_hub import snapshot_download
|
| 52 |
+
|
| 53 |
+
repo_path = snapshot_download(repo_id="ogutsevda/graphist")
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### 2. Build and load the model
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
import sys, torch
|
| 60 |
+
sys.path.insert(0, repo_path)
|
| 61 |
+
|
| 62 |
+
from models import build_model
|
| 63 |
+
|
| 64 |
+
class Args:
|
| 65 |
+
encoder = "acm_gin"
|
| 66 |
+
decoder = "acm_gin"
|
| 67 |
+
drop_edge_rate = 0.0
|
| 68 |
+
mask_rate = 0.5
|
| 69 |
+
replace_rate = 0.1
|
| 70 |
+
num_hidden = 512
|
| 71 |
+
num_layers = 5
|
| 72 |
+
num_heads = 4
|
| 73 |
+
num_out_heads = 1
|
| 74 |
+
residual = None
|
| 75 |
+
attn_drop = 0.1
|
| 76 |
+
in_drop = 0.2
|
| 77 |
+
norm = None
|
| 78 |
+
negative_slope = 0.2
|
| 79 |
+
batchnorm = False
|
| 80 |
+
activation = "prelu"
|
| 81 |
+
loss_fn = "sce"
|
| 82 |
+
alpha_l = 3
|
| 83 |
+
concat_hidden = True
|
| 84 |
+
num_features = 46
|
| 85 |
+
num_edge_features = 1
|
| 86 |
+
|
| 87 |
+
args = Args()
|
| 88 |
+
model = build_model(args)
|
| 89 |
+
checkpoint = torch.load(f"{repo_path}/graphist.pt", weights_only=False)
|
| 90 |
+
model.load_state_dict(checkpoint["model_state_dict"])
|
| 91 |
+
model.eval()
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### 3. Generate embeddings
|
| 95 |
+
|
| 96 |
+
```python
|
| 97 |
+
with torch.no_grad():
|
| 98 |
+
embeddings = model.embed(
|
| 99 |
+
batch.x, batch.edge_index, batch.edge_attr, batch.batch
|
| 100 |
+
)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
## Acknowledgements
|
| 104 |
+
|
| 105 |
+
The model architecture adapts code from [GraphMAE](https://github.com/THUDM/GraphMAE) and [ACM-GNN](https://github.com/SitaoLuan/ACM-GNN).
|
| 106 |
+
|
| 107 |
+
## Citation
|
| 108 |
+
|
| 109 |
+
```bibtex
|
| 110 |
+
@article{graphist2025,
|
| 111 |
+
title = {GrapHist: Graph Self-Supervised Learning for Histopathology},
|
| 112 |
+
author = {TODO},
|
| 113 |
+
journal = {TODO},
|
| 114 |
+
year = {2025},
|
| 115 |
+
}
|
| 116 |
+
```
|