MouseLand / suite2p

cell detection in calcium imaging recordings
http://www.suite2p.org
GNU General Public License v3.0
354 stars 241 forks source link

Cellpose error and out of memory error in suite2p 0.10.3 #915

Open ziyizhu1996 opened 1 year ago

ziyizhu1996 commented 1 year ago

Describe the issue:

When running suite2p 0.10.3 with green functional channel (chan1) and red structural channel (chan2), ROI detection based on green gcamp and anatomical_only set to 0, suite2p still tries to segment red ROIs using cellpose, but it gives an error:

CELLPOSE estimating masks in anatomical channel 1102 masks detected, median diameter = 10.22 ERROR importing or running cellpose, continuing without anatomical estimates

Further more, after that, suite2p tries to save some incredibly large data (asking for 40GB of memory allocation, while my imaging data is only 4GB with 2000 frames).

Reproduce the code example:

python -m suite2p

Error message:

ERROR importing or running cellpose, continuing without anatomical estimates
>>>ERROR<<<
Traceback (most recent call last):
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\runpy.py", line 194, in _run_module_as_main
>>>ERROR<<<
    return _run_code(code, main_globals, None,
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\site-packages\suite2p\__main__.py", line 78, in <module>
    main()
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\site-packages\suite2p\__main__.py", line 71, in main
    run_s2p(ops, db)
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\site-packages\suite2p\run_s2p.py", line 448, in run_s2p
    op = run_plane(op, ops_path=ops_path)
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\site-packages\suite2p\run_s2p.py", line 245, in run_plane
    ops, stat = detection.detect(ops=ops, classfile=classfile)
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\site-packages\suite2p\detection\detect.py", line 84, in detect
    ops, redcell = chan2detect.detect(ops, stat)
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\site-packages\suite2p\detection\chan2detect.py", line 105, in detect
    redstats = intensity_ratio(ops, stats)
  File "C:\Users\zzhu34\AppData\Local\Continuum\anaconda3\envs\suite2p\lib\site-packages\suite2p\detection\chan2detect.py", line 65, in intensity_ratio
    inpix = cell_masks @ mimg2.flatten()
numpy.core._exceptions.MemoryError: Unable to allocate 40.6 GiB for an array with shape (3202, 1700864) and data type float64
Interrupted by error (not finished)

Version information:

suite2p 0.10.3 cellpose 2.2

Context for the issue:

No response

carsen-stringer commented 1 year ago

it seems like your images are fairly big (1300 x 1300)? so this operation needs to be done in a loop

ziyizhu1996 commented 1 year ago

Yep this is from a mesoscope recording with multiple ROIs. Seems to have this issue with all my large recordings so makes sense.

carsen-stringer commented 1 year ago

In the meantime before this is fixed, you should run each ROI separately, I would recommend this regardless as this will make registration better as well. You can use this script: https://github.com/MouseLand/suite2p/blob/main/helpers/mesoscope_json_from_scanimage.m

ziyizhu1996 commented 1 year ago

that's cool. that's what I figured I should be doing. Thank you!