### Install cellSAM Library Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/reproducibility.md Install the cellSAM library from the parent directory after activating the virtual environment. ```bash pip install .. ``` -------------------------------- ### Manual Installation of Napari Dependencies Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/napari.md Manually install napari and PySide2 if you need finer-grained control over Qt bindings. ```bash pip install napari pyside2 magicgui ``` -------------------------------- ### Clone Repository Source: https://github.com/vanvalenlab/cellsam/blob/master/cellSAM/AnchorDETR/README.md Clone the AnchorDETR repository locally to get started. ```bash git clone https://github.com/megvii-research/AnchorDETR.git ``` -------------------------------- ### Install CellSAM Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/index.md Install the CellSAM package using pip. This command clones the repository and installs the package. ```bash pip install git+https://github.com/vanvalenlab/cellSAM.git ``` -------------------------------- ### Install CellSAM with Napari Dependencies Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/napari.md Install cellSAM with optional napari dependencies. This is the simplest way to ensure all necessary packages are installed. ```bash pip install .[napari] ``` -------------------------------- ### Install CellSAM from GitHub with Napari Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/napari.md Install cellSAM directly from GitHub, including napari dependencies, for the latest version. ```bash pip install "cellSAM[napari] @ git+https://github.com/vanvalenlab/cellSAM@master" ``` -------------------------------- ### Install Evaluation Dependencies Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/reproducibility.md Install the specific requirements for the evaluation suite using the provided requirements.txt file. This may downgrade some existing dependencies. ```bash pip install -r requirements.txt ``` -------------------------------- ### Unpack Evaluation Dataset with Parallel Decompression Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/reproducibility.md Unpack the downloaded dataset archive to a specified location, utilizing parallel decompression for efficiency. This example uses 8 threads and unpacks to the /data directory. ```bash tar --use-compress-program="unpigz -p 8" -xf $HOME/.deepcell/datasets/cellsam-data_v1.2.tar.gz -C /data ``` -------------------------------- ### Run the CellSAM Napari Plugin Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/napari.md Launch the napari application with the cellSAM plugin enabled from the command line. ```bash cellsam napari ``` -------------------------------- ### Run All Evaluations Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/reproducibility.md Execute the entire evaluation suite using the all_runs.sh script. Ensure model and dataset locations are correctly configured at the top of the script. ```bash ./all_runs.sh ``` -------------------------------- ### Create and Activate Python Virtual Environment Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/reproducibility.md Use Python's built-in venv module to create a new virtual environment for evaluation. Ensure you replace 'XX' with your desired Python version. ```bash python3.XX -m venv cs-eval-env source cs-eval-env/bin/activate ``` -------------------------------- ### Download Pretrained Model Weights Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/reproducibility.md Download and unpack the latest version of the pretrained model weights using the get_model function from the cellSAM library. Specify a version using `version=` for specific model weights. ```python from cellSAM import get_model get_model(); ``` -------------------------------- ### Download Training Data Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/API-key.md Use this function to download the training dataset, which is approximately 14GB. Ensure you have sufficient disk space and network bandwidth before proceeding. The compressed dataset will be stored in $HOME/.deepcell/data/cellsam/. ```python from cellSAM import download_training_data download_training_data() ``` -------------------------------- ### Visualize Bounding Box for Segmentation Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/tutorial.md Defines a bounding box and visualizes it on the input image. This is used to demonstrate how to prompt CellSAM for specific cell segmentation. ```python # Here's the cell we want to segment! box = [290, 365, 60, 38] # x, y, w, h rect = patches.Rectangle( (box[0], box[1]), box[2], box[3], linewidth=1, edgecolor='r', facecolor='none' ) plt.figure(figsize=(5, 5)) plt.imshow(img, cmap='gray') plt.gca().add_patch(rect); ``` -------------------------------- ### Train AnchorDETR (8 GPUs) Source: https://github.com/vanvalenlab/cellsam/blob/master/cellSAM/AnchorDETR/README.md Train the AnchorDETR model on a single node using 8 GPUs. Ensure the COCO dataset path is correctly specified. ```python python -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --coco_path /path/to/coco ``` -------------------------------- ### Initialize CellSAM Predictor and Segment Specific Cell Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/tutorial.md Initializes the CellSAM model and preprocesses the image. It then uses the provided bounding box to predict a mask for a specific cell. ```python predictor = get_model() # We can pass the bounding boxes to the model prediction function x1, y1, w, h = box # Bounding-box prompts should have format (x1, x2, y1, y2), where (x1, y1) is # the lower-left corner of the box and (x2, y2) is the upper right x2, y2 = x1 + w, y1 + h # Preprocess the image im = format_image_shape(img) im = normalize_image(im) im = np.transpose(im, (2, 0, 1)) im = np.expand_dims(im, axis=0) pred_mask, *_ = predictor.predict(im, boxes_per_heatmap=[[[x1, y1, x2, y2]]]) ``` -------------------------------- ### Import CellSAM Libraries Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/tutorial.md Imports necessary libraries for using CellSAM, including image processing and visualization tools. ```python import imageio.v3 as iio import numpy as np import scipy as sp import matplotlib.pyplot as plt import matplotlib.patches as patches from cellSAM import cellsam_pipeline, get_model from cellSAM.utils import format_image_shape, normalize_image ``` -------------------------------- ### Download Evaluation Dataset Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/reproducibility.md Initiate the download of the compressed evaluation dataset archive. The data will be saved to $HOME/.deepcell/datasets/. ```python from cellSAM import download_training_data download_training_data() ``` -------------------------------- ### Run CellSAM Inference Pipeline Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/tutorial.md Loads an image and runs the `cellsam_pipeline` to predict masks for all cells. This method automatically finds bounding boxes if none are provided. Performance is significantly better on a GPU. ```python # Load sample data and trim padding img = iio.imread("../sample_imgs/YeaZ.png")[8:-7, 8:-7] # Run inference pipeline mask = cellsam_pipeline( img, use_wsi=False, low_contrast_enhancement=False, gauge_cell_size=False ) # Visualize results plt.imshow(mask); ``` -------------------------------- ### Evaluate AnchorDETR (8 GPUs) Source: https://github.com/vanvalenlab/cellsam/blob/master/cellSAM/AnchorDETR/README.md Evaluate the trained AnchorDETR model on a single node with 8 GPUs. Specify the evaluation flag, COCO path, and the path to the pre-trained checkpoint. ```python python -m torch.distributed.launch --nproc_per_node=8 --use_env main.py --eval --coco_path /path/to/coco --resume /path/to/checkpoint.pth ``` -------------------------------- ### Evaluate AnchorDETR (Single GPU) Source: https://github.com/vanvalenlab/cellsam/blob/master/cellSAM/AnchorDETR/README.md Evaluate the trained AnchorDETR model using a single GPU. Provide the COCO dataset path and the checkpoint path. ```python python main.py --eval --coco_path /path/to/coco --resume /path/to/checkpoint.pth ``` -------------------------------- ### Perform Cell Segmentation Source: https://github.com/vanvalenlab/cellsam/blob/master/README.md Load a sample image and perform cellular segmentation using the `segment_cellular_image` function. Ensure you have a CUDA-enabled device for optimal performance. ```python import numpy as np from cellSAM import segment_cellular_image img = np.load("sample_imgs/yeaz.npy") mask, _, _ = segment_cellular_image(img, device='cuda') ``` -------------------------------- ### Set DeepCell Access Token Environment Variable Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/API-key.md Set the DEEPCELL_ACCESS_TOKEN environment variable with your token obtained from users.deepcell.org. This allows automatic access to DeepCell models and data upon login when added to your shell configuration. ```bash export DEEPCELL_ACCESS_TOKEN= ``` -------------------------------- ### CellSAM Citation Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/index.md BibTeX entry for citing the CellSAM foundation model in academic work. ```latex @article{israel2023foundation, title={A Foundation Model for Cell Segmentation}, author={Israel, Uriah and Marks, Markus and Dilip, Rohit and Li, Qilin and Schwartz, Morgan and Pradhan, Elora and Pao, Edward and Li, Shenyi and Pearson-Goulart, Alexander and Perona, Pietro and others}, journal={bioRxiv}, publisher={Cold Spring Harbor Laboratory Preprints}, doi = {10.1101/2023.11.17.567630}, } ``` -------------------------------- ### Anchor DETR Citation Source: https://github.com/vanvalenlab/cellsam/blob/master/cellSAM/AnchorDETR/README.md Cite the Anchor DETR paper in your research if this project is useful. Includes author, title, booktitle, volume, number, pages, and year. ```bibtex @inproceedings{wang2022anchor, title={Anchor detr: Query design for transformer-based detector}, author={Wang, Yingming and Zhang, Xiangyu and Yang, Tong and Sun, Jian}, booktitle={Proceedings of the AAAI Conference on Artificial Intelligence}, volume={36}, number={3}, pages={2567--2575}, year={2022} } ``` -------------------------------- ### Visualize Predicted Cell Mask Source: https://github.com/vanvalenlab/cellsam/blob/master/docs/tutorial.md Superimposes the predicted cell mask as an edge onto the original image for clear visualization. This helps in verifying the segmentation accuracy. ```python # Use several iterations to make the mask edge visible when plotting dilated_mask = sp.ndimage.binary_dilation(pred_mask > 0, iterations=5) edges = (dilated_mask > pred_mask).astype(np.uint8) # Plot the image plt.imshow(img, cmap="gray") # And the outlines from the mask plt.imshow(255 * edges, cmap="Reds", alpha=edges); ``` -------------------------------- ### CellSAM Citation Source: https://github.com/vanvalenlab/cellsam/blob/master/README.md BibTeX entry for citing the CellSAM paper. Please cite this work when using CellSAM in your research. ```bibtex @article{israel2023foundation, title={A Foundation Model for Cell Segmentation}, author={Israel, Uriah and Marks, Markus and Dilip, Rohit and Li, Qilin and Schwartz, Morgan and Pradhan, Elora and Pao, Edward and Li, Shenyi and Pearson-Goulart, Alexander and Perona, Pietro and others}, journal={bioRxiv}, publisher={Cold Spring Harbor Laboratory Preprints}, doi = {10.1101/2023.11.17.567630}, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.