BiomedSciAI / histocartography

A standardized Python API with necessary preprocessing, machine learning and explainability tools to facilitate graph-analytics in computational pathology.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory issues with Nuclei Extractor

hossam-zaki opened this issue · comments

Hello! Really loving the package. I'm working on scaling this to more images, and am finding that the program uses a crazy amount of memory. The progress bar for the nuclei extractor gets to 100%, it hangs, then my program kills it because it surpasses the memory allocated for it (for reference, I have allocated 200GB). The image that I'm using is around 50MB, which could be causing this. Here's the image: https://drive.google.com/file/d/1HThowD4uzjJz9nZ7QYaBcdpiB2e9ZPMP/view?usp=sharing

This is the code that I'm using:

image_fnames = glob(os.path.join(image_path, '*[!A].jpg'))

print(image_fnames)
# 2. define nuclei extractor
nuclei_detector = NucleiExtractor()

# 3. define feature extractor: Extract patches of 72x72 pixels around each
# nucleus centroid, then resize to 224 to match ResNet input size.
feature_extractor = DeepFeatureExtractor(
    architecture='resnet34',
    patch_size=72,
    resize_size=224,
)

# 4. define k-NN graph builder with k=5 and thresholding edges longer
# than 50 pixels. Add image size-normalized centroids to the node features.
# For e.g., resulting node features are 512 features from ResNet34 + 2
# normalized centroid features.
knn_graph_builder = KNNGraphBuilder(k=5, thresh=50, add_loc_feats=True)

# 5. define graph visualizer
visualizer = OverlayGraphVisualization()

# 6. process all the images
for image_path in tqdm(image_fnames):

    # a. load image
    _, image_name = os.path.split(image_path)
    image = np.array(Image.open(image_path))

    # b. extract nuclei
    nuclei_map, centroids = nuclei_detector.process(image)

Any help is appreciated!!

Hi,

do you have a CPU or GPU memory issue? Also are you able to identify what part of the code is creating it?