Download scripts/packets/pool_best_p_packets.py from thanminh01/WSI_Packets: direct link, hf CLI and curl.
- Browser
- Download file 1.2 kB
-
https://huggingface.co/datasets/thanminh01/WSI_Packets/resolve/main/scripts/packets/pool_best_p_packets.py
- Command line
-
hf download hf://datasets/thanminh01/WSI_Packets/scripts/packets/pool_best_p_packets.py
-
curl -L -o pool_best_p_packets.py https://huggingface.co/datasets/thanminh01/WSI_Packets/resolve/main/scripts/packets/pool_best_p_packets.py
1.2 kB
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import torch | |
| ROOT = Path(__file__).resolve().parents[3] | |
| sys.path.insert(0, str(ROOT / 'comparators/ProKeR-PTA')) | |
| from proker_pta.data import POOLED, pooled_file, raw_packet | |
| # writes the slide packet pooled at the best Top-P of each cell, so a machine without the 39 GB of ranked patch sets can run the best Top-P settings | |
| def main(): | |
| ap = argparse.ArgumentParser(description='Pool the ranked patch sets at the best Top-P into small slide packets.') | |
| ap.add_argument('--datasets', nargs='+') | |
| ap.add_argument('--redo', action='store_true') | |
| a = ap.parse_args() | |
| cells = json.loads((ROOT / 'experiments/miscellaneous/shared/cells.json').read_text())['best'] | |
| POOLED.mkdir(parents=True, exist_ok=True) | |
| for key, cell in cells.items(): | |
| path = pooled_file(cell) | |
| if cell['top_p'] == 1 or (a.datasets and cell['dataset'] not in a.datasets) or (path.exists() and not a.redo): | |
| continue | |
| raw = raw_packet(cell) | |
| torch.save(raw, path) | |
| print(f"{key} P{cell['top_p']}: {path.name} {path.stat().st_size / 1e6:.0f} MB", flush=True) | |
| if __name__ == '__main__': | |
| main() | |