### Install Kaggle CLI Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/assets/readmes/Datasets_acquisition.md Install the Kaggle command-line interface using pip. Required before downloading the Lizard dataset via the Kaggle CLI option. ```bash pip install kaggle ``` -------------------------------- ### Run training Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Starts training. Modify SAVE_DIR and RESUME_FROM in configs/pathsegmentor.yaml to set output paths. ```bash bash scripts/train.sh ``` -------------------------------- ### Install model dependencies with --no-build-isolation Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Installs model dependencies. Build isolation is disabled because the pinned custom Detectron2 build imports PyTorch during compilation. ```bash python -m pip install --no-build-isolation -r requirements.txt ``` -------------------------------- ### Download Lizard dataset with Kaggle CLI Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/assets/readmes/Datasets_acquisition.md Downloads and unzips the Lizard dataset to /Lizard. Requires kaggle.json placed in ~/.kaggle/ beforehand. ```bash kaggle datasets download -p /Lizard aadimator/lizard-dataset --unzip ``` -------------------------------- ### Set up PathSegmentor environment with Conda Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Creates the project environment used by PathSegmentor. Requires Python 3.11, PyTorch 2.1.0, torchvision 0.16.0, and CUDA 12.1 on Linux. ```bash git clone https://github.com/zhi-xuan-chen/PathSegmentor.git cd PathSegmentor conda env create -f environment.yml conda activate pathsegmentor ``` -------------------------------- ### Generate dataset info for multiple datasets Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Generates dataset info JSON files for multiple datasets at once. Update the 'dataset_paths' list with the paths to all datasets. ```bash cd pathseg_datasets python create_multiple_dataset.py ``` -------------------------------- ### Run evaluation Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Evaluates the fine-tuned model using the test set. Customize output directory in trainer/default_trainer.py around line 79. ```bash bash scripts/eval.sh ``` -------------------------------- ### Generate dataset info for a single dataset Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Generates dataset info JSON files for a single dataset. Set the 'targetpath' parameter to your dataset path before running. ```bash cd pathseg_datasets python create_single_dataset.py ``` -------------------------------- ### Download NLTK resources for language encoder Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Downloads the NLTK resources (punkt and averaged_perceptron_tagger) used by the language encoder. ```bash python -m nltk.downloader punkt averaged_perceptron_tagger ``` -------------------------------- ### Dataset directory after generating JSONs Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Directory structure after generating the JSON files. The train.json and test.json are used for training and testing respectively. ```text pathseg_datasets ├── [DATASET_NAME] │ ├── train │ ├── train_mask │ ├── train.json │ ├── test │ ├── test_mask │ └── test.json ``` -------------------------------- ### Image filename format Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Filename format for image patches. Replace [IMAGE-NAME] and [REGION] with a unique identifier and anatomical region. Images must be 1024x1024 patches at 40x magnification. ```text [IMAGE-NAME]_pathology_[REGION].png ``` -------------------------------- ### Run PathSegmentor Inference on Pathology Image Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/inference_examples.ipynb Loads a pathology image and its ground truth mask, runs inference with a text prompt 'tissue-level gland in colon pathology', and plots the predicted segmentation mask over the image. The ground truth mask is read as RGB and the red channel is used as the single-channel mask. The output is a matplotlib figure with size 800x400. ```python # Pathology Example image_path = '/home/chenzhixuan/Workspace/PathSegmentor/examples/1_irregular/2/test181_pathology_colon.png' mask_path = '/home/chenzhixuan/Workspace/PathSegmentor/examples/1_irregular/2/test181_pathology_colon_tissue+gland.png' text_prompt = ['tissue-level gland in colon pathology'] image, pred_mask = inference_rgb(image_path, text_prompt) gt_mask = read_rgb(mask_path) gt_mask = gt_mask[:, :, 0] # Assuming the GT mask is a single channel colors = [[255, 0, 0]] # Plot feature over image plot_segmentation_masks(image, pred_mask, text_prompt, colors = colors) ``` -------------------------------- ### Dataset directory structure Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md The required directory structure for each dataset inside pathseg_datasets. The train and train_mask folders contain training images and masks, while test and test_mask hold testing images and masks. ```text pathseg_datasets ├── [DATASET_NAME] │ ├── train │ ├── train_mask │ ├── test │ └── test_mask ``` -------------------------------- ### Mask filename format Source: https://github.com/zhi-xuan-chen/pathsegmentor/blob/main/README.md Filename format for mask files. The initial part matches the corresponding image; [OBJECT] replaces spaces with '+' and its first component indicates the histological structure (e.g., 'nuclei+neoplastic'). ```text [IMAGE-NAME]_pathology_[REGION]_[OBJECT].png ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.