Skip to content

bin2cell.stardist: Found 0 objects #71

Open

Description

@liangxs7015

Hi, thanks for develping this tool for us. I have to report a issue during bin2cell.stardist for my 10X HD Visium sample segment. The bin2cell.stardist produced "Found 0 objects" whether I load square_008um or square_002um data
import numpy as np
import matplotlib.pyplot as plt
import scanpy as sc
import tensorflow
import os
import collections
import bin2cell as b2c
import pandas as pd
import gc

#set the path
path = "/home/data/Data_Storage/COAD/n2023262/binned_outputs/square_008um/"
#the image you used for --image of spaceranger, that's the one the spatial coordinates are based on
source_image_path = "/home/data/Data_Storage/Source_image_b2cell/n2023262.jpg"
spaceranger_image_path = "/home/data/Data_Storage/COAD/n2023262/binned_outputs/square_008um/spatial"

#read data
n2023262= b2c.read_visium(path,
source_image_path = source_image_path,
spaceranger_image_path = spaceranger_image_path
)
n2023262.var_names_make_unique()

#filtration
sc.pp.filter_genes(n2023262, min_cells=3)
sc.pp.filter_cells(n2023262, min_counts=1)
n2023262

#scale
mpp = 0.5
b2c.scaled_he_image(n2023262, mpp=mpp, save_path="/home/data/liangxs/R_project/a_Ongoing_SpatialHD/Jupyter/stardist/n2023262_he.tiff")

b2c.destripe(n2023262)

###All the above steps went well
###However, the b2c.stardist produced "Found 0 objects":
b2c.stardist(image_path="/home/data/liangxs/R_project/a_Ongoing_SpatialHD/Jupyter/stardist/n2023262_he.tiff",
labels_npz_path="/home/data/liangxs/R_project/a_Ongoing_SpatialHD/Jupyter/stardist/n2023262_he.npz",
stardist_model="2D_versatile_he",
prob_thresh=0.01
)

_function_base_impl.py (107): overflow encountered in cast
_function_base_impl.py (4750): overflow encountered in cast
_function_base_impl.py (4655): invalid value encountered in multiply
_function_base_impl.py (4656): invalid value encountered in scalar multiply
Found model '2D_versatile_he' for 'StarDist2D'.
Loading network weights from 'weights_best.h5'.
Loading thresholds from 'thresholds.json'.
Using default values: prob_thresh=0.692478, nms_thresh=0.3.
Overriding with prob_thresh=0.01
effective: block_size=(4096, 4096, 3), min_overlap=(128, 128, 0), context=(128, 128, 0)
100%|██████████| 16/16 [01:46<00:00, 6.65s/it]
Found 0 objects

bin2cell version: '0.3.4'

How to solve this problem, please~

Activity

  1. ktpolanski commented on Nov 2, 2025

    @ktpolanski
    Contributor
    _function_base_impl.py (107): overflow encountered in cast
    _function_base_impl.py (4750): overflow encountered in cast
    _function_base_impl.py (4655): invalid value encountered in multiply
    _function_base_impl.py (4656): invalid value encountered in scalar multiply

    This part I haven't seen before. I did a little googling and came across this: numpy/numpy#29003

    I then tested out the minimal working example they provide with a few different versions of numpy:

    import numpy as np
    arr = np.zeros(65521, dtype=np.float16)
    arr[:10] = 1
    z = np.percentile(arr, 50)

    The cutoff I found locally is 2.0.0 - the code ran fine on 1.26.4 and blew up on 2.0.0 (and some higher ones I tried). You should have sub-2.x numpy as per the [stardist] specification of the installation, plus from what I remember StarDist just blows up completely if you try to run it with 2.x numpys. What version do you have?

  2. liangxs7015 commented on Nov 2, 2025

    @liangxs7015
    Author

    Really aprreciate your quick response! My numpy version is 2.2.6 and I downgraded it to 1.26.4. However, a new report was produced 'module 'keras.backend' has no attribute 'abs''. I'm trying other numpy versions to see if this could solved this issue. Thanks

  3. ktpolanski commented on Nov 2, 2025

    @ktpolanski
    Contributor

    I don't understand how you ended up in this position, but good that it helped. The new thing you're encountering seems to be tensorflow/stardist related. May I recommend just making a fresh conda environment? I tend to usually use python 3.10, so you can use that one if you want. Then all you'd need to do would be:

    pip install bin2cell[stardist]
    pip install tensorflow
  4. liangxs7015 commented on Nov 2, 2025

    @liangxs7015
    Author

    Yes it seems hard to handle this in current env, I'll try a fresh conda env with python 3.10, thanks a lot

  5. liangxs7015 commented on Nov 6, 2025

    @liangxs7015
    Author

    Back here to report that creating an fresh conda env with 'pip install bin2cell[stardist]' and 'pip install tensorflow' finally solved the problem. Really grateful!

  6. ktpolanski commented on Nov 11, 2025

    @ktpolanski
    Contributor

    As for the initial numpy bug you ran into, it seems that it's on track to be patched in 2.4.0. I'll leave the issue open to act as a reminder for when StarDist updates itself to work with 2.x numpys at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions