### Setup Conda Environment and Install PyTorch Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/README.md This snippet shows how to create a conda environment from an 'environment.yml' file, activate it, and then install specific versions of PyTorch and Torchvision for CUDA 11.8. ```bash conda env create -f environment.yml conda activate hovernext pip install torch==2.1.1 torchvision==0.16.1 --index-url https://download.pytorch.org/whl/cu118 ``` -------------------------------- ### Run Docker/Singularity Container Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/README.md Command to download the Singularity image for HoVer-Next inference. ```bash singularity run --nv hover_next.sif ``` -------------------------------- ### Run Inference on TCGA Sample Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/sample_analysis.ipynb Initiates the main inference process with specified parameters. Ensure the 'main' module is correctly imported. ```python import zarr import numpy as np import json from main import main ''' Run inference on a small sample image from TCGA ''' params = { } main(params) ``` -------------------------------- ### Load Instance Map from Zarr Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/sample_analysis.ipynb Opens a Zarr file for interaction with instance map data. Supports ROI selection or full array loading. ```python ''' Instance map: 2D full-size matrix where each pixels value corresponds to the associated instance (value>0) or background (value=0) ''' # open: file-like interaction with zarr-array instance_map = zarr.open("pinst_pp.zip", mode="r") # selecting a ROI will yield a numpy array roi = instance_map[10000:20000,10000:20000] # or with [:] to load the entire array full_instance_map = instance_map[:] # alternatively, use load, which will directly create a numpy array: full_instance_map = zarr.load("pinst_pp.zip") ``` -------------------------------- ### Run HoVer-NeXt Inference with Apptainer Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/README.md Execute the HoVer-NeXt inference pipeline using Apptainer. Ensure your local directory is mounted to APPTAINER_BINDPATH. This command processes SVS images and saves results. ```bash export APPTAINER_BINDPATH="/storage" apptainer exec --nv /path-to-container/hover_next.sif \ python3 /path-to-repo/main.py \ --input "/path-to-wsi/*.svs" \ --output_root "results/" --cp "lizard_convnextv2_large" \ --tta 4 ``` -------------------------------- ### Create Class Map using Lookup Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/sample_analysis.ipynb Generates a class map by creating a lookup array from class information and applying it to the full instance map. ```python # or alternatively create a lookup for the instance map to get a corresponding class map pcls_list = np.array([0] + [v[0] for v in class_info.values()]) pcls_keys = np.array(["0"] + list(class_info.keys())).astype(int) lookup = np.zeros(pcls_keys.max() + 1,dtype=np.uint8) lookup[pcls_keys] = pcls_list cls_map = lookup[full_instance_map] ``` -------------------------------- ### Load Class Information and Create Centroid Array Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/sample_analysis.ipynb Loads class information from a JSON file and constructs a NumPy array containing instance IDs, class IDs, and centroid coordinates. ```python ''' Class dictionary: Lookup for the instance map, also contains centroid coordinates. If only centroid coordinates are of interest, you can skip loading the instance map. ''' # load the dictionary with open("class_inst.json","r") as f: class_info = json.load(f) # create a centroid info array centroid_array = np.array([[int(k),v[0],*v[1]] for k,v in class_info.items()]) # [instance_id, class_id, y, x] ``` -------------------------------- ### Run WSI Inference Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/README.md Command to perform inference on a single Whole Slide Image (WSI) using specified input, output, model checkpoint, and various inference parameters. Adjust parameters like '--inf_workers' and '--pp_workers' based on your machine's cores. ```bash python3 main.py \ --input "/path-to-wsi/wsi.svs" \ --output_root "results/" \ --cp "lizard_convnextv2_large" \ --tta 4 \ --inf_workers 16 \ --pp_tiling 10 \ --pp_workers 16 ``` -------------------------------- ### Run NPY or Image Inference Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/README.md Command to perform inference on NPY or common image files. The output will be a ZARR array. Similar to WSI inference, optimize worker and tiling parameters for your system. ```bash python3 main.py \ --input "/path-to-file/file.npy" \ --output_root "/results/" \ --cp "lizard_convnextv2_large" \ --tta 4 \ --inf_workers 16 \ --pp_tiling 10 \ --pp_workers 16 ``` -------------------------------- ### HoVer-NeXt Citation Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/README.md Citation for the HoVer-NeXt paper published in Medical Imaging with Deep Learning. ```bibtex @inproceedings{baumann2024hover, title={HoVer-NeXt: A Fast Nuclei Segmentation and Classification Pipeline for Next Generation Histopathology}, author={Baumann, Elias and Dislich, Bastian and Rumberger, Josef Lorenz and Nagtegaal, Iris D and Martinez, Maria Rodriguez and Zlobec, Inti}, booktitle={Medical Imaging with Deep Learning}, year={2024} } ``` -------------------------------- ### Panoptic Segmentation Citation Source: https://github.com/digitalpathologybern/hover_next_inference/blob/main/README.md Citation for the Panoptic segmentation paper. ```bibtex @INPROCEEDINGS {"rumberger2022panoptic", author={Rumberger, Josef Lorenz and Baumann, Elias and Hirsch, Peter and Janowczyk, Andrew and Zlobec, Inti and Kainmueller, Dagmar}, booktitle={2022 IEEE International Symposium on Biomedical Imaging Challenges (ISBIC)}, title={Panoptic segmentation with highly imbalanced semantic labels}, year={2022}, pages={1-4}, doi={10.1109/ISBIC56247.2022.9854551}} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.