a12donhf commited on
Commit
f6f8194
·
verified ·
1 Parent(s): 5d71601

Add paper figures and a runnable single-tile example

Browse files
.gitattributes CHANGED
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/morphology_controls.png filter=lfs diff=lfs merge=lfs -text
37
+ assets/pipeline.png filter=lfs diff=lfs merge=lfs -text
38
+ assets/spatial_fidelity.png filter=lfs diff=lfs merge=lfs -text
39
+ examples/paper_tile/reference_generated.png filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -22,7 +22,6 @@ base_model_relation: finetune
22
  - **Code and complete instructions:** [a12dongithub/PathOGen](https://github.com/a12dongithub/PathOGen)
23
  - **Model repository:** [a12donhf/CPathOGen](https://huggingface.co/a12donhf/CPathOGen)
24
  - **Authors:** Samarth Singhal and Varang Rai
25
- - **Paper:** arXiv link will be added after submission.
26
 
27
  ## What the model does
28
 
@@ -32,7 +31,64 @@ Researchers can keep diffusion noise fixed, change a requested control, and comp
32
 
33
  The checkpoint uses latent concatenation with a learned spatial encoder. It is not a standard Diffusers `ControlNetModel` or standalone `DiffusionPipeline` checkpoint.
34
 
35
- ## Run inference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  Use Python 3.10/3.11, a compatible CUDA-enabled PyTorch build, and an NVIDIA GPU.
38
 
@@ -83,6 +139,17 @@ checkpoint-30000/
83
  vae/diffusion_pytorch_model.safetensors
84
  film_mlps.pt
85
  spatial_encoder.pt
 
 
 
 
 
 
 
 
 
 
 
86
  ```
87
 
88
  The FiLM and spatial-encoder files contain PyTorch state dictionaries and are loaded with `weights_only=True`. Optimizer, scheduler training state, and random-state pickle files are excluded. Original weights are preserved; the checkpoint is not quantized or converted. `release_manifest.json` records per-file SHA-256 hashes and sizes.
@@ -107,3 +174,5 @@ Research uses include controlled histopathology synthesis and probing model sens
107
  ## License
108
 
109
  Model weights retain the CreativeML Open RAIL++-M terms inherited from Stable Diffusion 2.1; see `LICENSE-MODEL`. Third-party software, analyzers, and datasets retain their respective licenses and access requirements.
 
 
 
22
  - **Code and complete instructions:** [a12dongithub/PathOGen](https://github.com/a12dongithub/PathOGen)
23
  - **Model repository:** [a12donhf/CPathOGen](https://huggingface.co/a12donhf/CPathOGen)
24
  - **Authors:** Samarth Singhal and Varang Rai
 
25
 
26
  ## What the model does
27
 
 
31
 
32
  The checkpoint uses latent concatenation with a learned spatial encoder. It is not a standard Diffusers `ControlNetModel` or standalone `DiffusionPipeline` checkpoint.
33
 
34
+ ## Figures from the paper
35
+
36
+ ![Controllable image generation and recorded black-box predictions for post-hoc interpretation](assets/principle.png)
37
+
38
+ **Counterfactual probing:** change a control, generate a matched image, and measure the downstream model's prediction response.
39
+
40
+ ![CPathOGen pipeline from CellViT++ weak labels to spatial and morphology-conditioned latent diffusion](assets/pipeline.png)
41
+
42
+ **Generation pipeline:** CellViT++ supplies cellular maps and morphology/appearance summaries; the spatial encoder and FiLM condition latent diffusion synthesis.
43
+
44
+ ![Three examples showing the cell map, real H&E tile, and generated H&E tile](assets/spatial_fidelity.png)
45
+
46
+ **Spatial examples:** input maps, associated real tiles, and condition-matched generated tiles from the paper. Map colors are tumor (white), immune (cyan), stroma (green), dead (yellow), and non-neoplastic epithelium (orange).
47
+
48
+ ![Five-level sweeps of nuclear size, eccentricity, solidity, gradient, and RGB appearance](assets/morphology_controls.png)
49
+
50
+ **Morphology and appearance examples:** the paper's five-level control sweeps. Most columns use relative standardized offsets; the historical eccentricity illustration instead uses absolute standardized coordinates with 20 steps and spatial strength 1. Nuclear size changes area and perimeter together. These are paper illustrations, not new generations from the quickstart.
51
+
52
+ ## Run one real example in Colab
53
+
54
+ Select a **GPU runtime** in Colab, then run the cell below. It downloads one prepared paper-tile condition, so you do not need the full dataset, Google Drive, or CellViT++ to try the generator. The public weights require no Hugging Face token.
55
+
56
+ ```python
57
+ from pathlib import Path
58
+ import torch
59
+
60
+ if not torch.cuda.is_available():
61
+ raise RuntimeError("Select Runtime > Change runtime type > GPU in Colab.")
62
+
63
+ %cd /content
64
+ if not Path("/content/CPathOGen-example/.git").is_dir():
65
+ !git clone -q --depth 1 https://github.com/a12dongithub/PathOGen.git /content/CPathOGen-example
66
+ %cd /content/CPathOGen-example
67
+ %pip install -q -r inference/requirements.txt
68
+
69
+ from huggingface_hub import hf_hub_download
70
+ from IPython.display import display
71
+ from PIL import Image
72
+
73
+ MODEL_ID = "a12donhf/CPathOGen"
74
+ map_path = hf_hub_download(MODEL_ID, "examples/paper_tile/map.npz")
75
+ morphology_path = hf_hub_download(MODEL_ID, "examples/paper_tile/morphology.json")
76
+ preview_path = hf_hub_download(MODEL_ID, "examples/paper_tile/input_map.png")
77
+
78
+ !python inference/generate.py --spatial-map "{map_path}" --morphology-json "{morphology_path}" --tile TCGA-E2-A15D_x46080_y24576_TR --seed 1872879198 --steps 30 --spatial-strength 2 --output outputs/paper_example.png
79
+
80
+ print("Input spatial map")
81
+ display(Image.open(preview_path))
82
+ print("Generated H&E")
83
+ display(Image.open("outputs/paper_example.png"))
84
+ print("Controls and run metadata: outputs/paper_example.json")
85
+ ```
86
+
87
+ The first run downloads approximately **4.16 GB of generator weights**, plus the base-model text encoder, tokenizer, and scheduler. Downloads are cached. This produces one 512 x 512 PNG and its condition/provenance JSON; it does not run eight-seed selection or downstream probing. Keep the seed fixed when comparing edited controls. Exact pixels can differ across hardware and numerical precision.
88
+
89
+ This model card documents GPU inference through the project code; it is not a hosted Hugging Face inference widget.
90
+
91
+ ## Local inference and custom inputs
92
 
93
  Use Python 3.10/3.11, a compatible CUDA-enabled PyTorch build, and an NVIDIA GPU.
94
 
 
139
  vae/diffusion_pytorch_model.safetensors
140
  film_mlps.pt
141
  spatial_encoder.pt
142
+ assets/
143
+ principle.png
144
+ pipeline.png
145
+ spatial_fidelity.png
146
+ morphology_controls.png
147
+ examples/paper_tile/
148
+ map.npz
149
+ morphology.json
150
+ metadata.json
151
+ input_map.png
152
+ reference_generated.png
153
  ```
154
 
155
  The FiLM and spatial-encoder files contain PyTorch state dictionaries and are loaded with `weights_only=True`. Optimizer, scheduler training state, and random-state pickle files are excluded. Original weights are preserved; the checkpoint is not quantized or converted. `release_manifest.json` records per-file SHA-256 hashes and sizes.
 
174
  ## License
175
 
176
  Model weights retain the CreativeML Open RAIL++-M terms inherited from Stable Diffusion 2.1; see `LICENSE-MODEL`. Third-party software, analyzers, and datasets retain their respective licenses and access requirements.
177
+
178
+ Paper figures are shared under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) with attribution to Samarth Singhal and Varang Rai; see [assets/README.md](assets/README.md). This does not change the model-weight license.
assets/README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ # Paper figures
2
+
3
+ These figures accompany **CPathOGen: Spatially and Morphologically Controlled H&E Counterfactuals for Probing Pathology Models**, by Samarth Singhal and Varang Rai.
4
+
5
+ - `principle.png`: rendered from paper Figure 1.
6
+ - `pipeline.png`: rendered from paper Figure 2.
7
+ - `spatial_fidelity.png`: assembled from the same tile assets used in paper Figure 3, with matching cell-color legend.
8
+ - `morphology_controls.png`: assembled from the same tile assets used in paper Figure 4. Dose labels are shortened to standardized control coordinates; eccentricity uses the paper image package's historical absolute-coordinate sweep.
9
+
10
+ Figure artwork is shared under [Creative Commons Attribution 4.0 International](https://creativecommons.org/licenses/by/4.0/). Attribute the authors and indicate changes when adapting the artwork. Third-party datasets retain their original terms. The generator weights remain under their separate CreativeML Open RAIL++-M license.
assets/morphology_controls.png ADDED

Git LFS Details

  • SHA256: ef9c8abb1b8f7adac0ff99a396f63dc8089556b3d16942358944d8162c60ce42
  • Pointer size: 132 Bytes
  • Size of remote file: 4.42 MB
assets/pipeline.png ADDED

Git LFS Details

  • SHA256: 32e4091b69c9403370e1ab5fddba1089c85b962bf02ab936303ac358316e4b72
  • Pointer size: 131 Bytes
  • Size of remote file: 431 kB
assets/principle.png ADDED
assets/spatial_fidelity.png ADDED

Git LFS Details

  • SHA256: 18b1fa138b87eb850ac1b765f461183a35c36a87a98206d057d92c0433825873
  • Pointer size: 132 Bytes
  • Size of remote file: 2 MB
examples/paper_tile/README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Single paper-tile example
2
+
3
+ Tile: `TCGA-E2-A15D_x46080_y24576_TR`.
4
+
5
+ - `map.npz`: the original five-channel spatial condition, using the `map` key and shape `(512, 512, 5)`.
6
+ - `morphology.json`: 16 already standardized morphology/appearance values, in the checkpoint's feature order.
7
+ - `input_map.png`: the paper visualization; use the NPZ, not this RGB preview, for inference.
8
+ - `reference_generated.png`: the previously generated paper-package baseline, not a new inference result.
9
+ - `metadata.json`: seed, sampling settings, channel order, and condition provenance.
10
+
11
+ Use seed `1872879198`, `30` steps, and spatial strength `2`. Different hardware or precision can yield different pixels. This example needs neither the full dataset nor a nucleus analyzer. Follow the Colab cell in the model card to generate a new image from these conditions.
examples/paper_tile/input_map.png ADDED
examples/paper_tile/map.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9931a70d066f7110351b412205248e0a8039a0415bce37fff9645e09ff2c9676
3
+ size 13900
examples/paper_tile/metadata.json ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "tile": "TCGA-E2-A15D_x46080_y24576_TR",
3
+ "seed": 1872879198,
4
+ "steps": 30,
5
+ "spatial_strength": 2.0,
6
+ "morphology_representation": "standardized training feature coordinates",
7
+ "channel_order": [
8
+ "neoplastic",
9
+ "inflammatory",
10
+ "connective",
11
+ "dead",
12
+ "epithelial"
13
+ ],
14
+ "spatial_shape": [
15
+ 512,
16
+ 512,
17
+ 5
18
+ ],
19
+ "map_sha256": "9931a70d066f7110351b412205248e0a8039a0415bce37fff9645e09ff2c9676",
20
+ "source": "Condition and generated baseline used in the paper image package",
21
+ "green_offset_standardized_units": 0.0,
22
+ "reference_note": "Fixed controls and seed; pixel-identical output is not guaranteed across hardware or precision."
23
+ }
examples/paper_tile/morphology.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "area_mean": -0.09236620366573334,
3
+ "area_var": -0.4095771014690399,
4
+ "eccentricity_mean": -1.2148321866989136,
5
+ "eccentricity_var": -0.3638562858104706,
6
+ "solidity_mean": 1.5003626346588135,
7
+ "solidity_var": -1.0003763437271118,
8
+ "perimeter_mean": -0.141899973154068,
9
+ "perimeter_var": -0.5273236632347107,
10
+ "grad_mean": 0.37052053213119507,
11
+ "grad_var": 0.22863806784152985,
12
+ "r_mean": 0.33253344893455505,
13
+ "r_var": 1.0801981687545776,
14
+ "g_mean": 0.21002225577831268,
15
+ "g_var": 0.5473105311393738,
16
+ "b_mean": 0.2969951629638672,
17
+ "b_var": 0.6543741822242737
18
+ }
examples/paper_tile/reference_generated.png ADDED

Git LFS Details

  • SHA256: f3435a2fd955a6e0442021dc61ee3a5dd749775a3d4d2704836da34ff5c5fee7
  • Pointer size: 131 Bytes
  • Size of remote file: 500 kB