Repository navigation
Description
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
ktpolanski commentedon Nov 2, 2025
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:
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?liangxs7015 commentedon Nov 2, 2025
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
ktpolanski commentedon Nov 2, 2025
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:
liangxs7015 commentedon Nov 2, 2025
Yes it seems hard to handle this in current env, I'll try a fresh conda env with python 3.10, thanks a lot
liangxs7015 commentedon Nov 6, 2025
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!
ktpolanski commentedon Nov 11, 2025
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.