flatironinstitute / CaImAn

Computational toolbox for large scale Calcium Imaging Analysis, including movie handling, motion correction, source extraction, spike deconvolution and result visualization.
https://caiman.readthedocs.io
GNU General Public License v2.0
641 stars 370 forks source link

cannot reshape array of size 0 into shape (0) #244

Closed xhonial closed 6 years ago

xhonial commented 6 years ago

Hi,

I'm running demo_pipeline_cnmfE with my data (it previously worked with the demo data), and I got the an error when I ran the following portion of the code: untitled

The error is the following:

untitled1

And this is what I get when I replace dview with None: ValueError Traceback (most recent call last)

in () 24 del_duplicates=True) # whether to remove duplicates from initialization 25 ---> 26 cnm.fit(Y) ~\Anaconda3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\cnmf.py in fit(self, images) 565 gnb=self.gnb, border_pix=self.border_pix, 566 low_rank_background=self.low_rank_background, --> 567 del_duplicates=self.del_duplicates) 568 569 # options = CNMFSetParms(Y, self.n_processes, p=self.p, gSig=self.gSig, K=A.shape[ ~\Anaconda3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\map_reduce.py in run_CNMF_patches(file_name, shape, options, rf, stride, gnb, dview, memory_fact, border_pix, low_rank_background, del_duplicates) 276 277 else: --> 278 file_res = list(map(cnmf_patches, args_in)) 279 280 print((time.time() - st)) ~\Anaconda3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\map_reduce.py in cnmf_patches(args_in) 152 init_iter=options['init_params']['init_iter']) 153 --> 154 cnm = cnm.fit(images) 155 return [idx_, shapes, scipy.sparse.coo_matrix(cnm.A), 156 cnm.b, cnm.C, cnm.f, cnm.S, cnm.bl, cnm.c1, ~\Anaconda3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\cnmf.py in fit(self, images) 454 if self.center_psf: 455 self.Ain, self.Cin, self.b_in, self.f_in, center, extra_1p = initialize_components( --> 456 Y, sn=sn, options_total=options, **options['init_params']) 457 else: 458 self.Ain, self.Cin, self.b_in, self.f_in, center = initialize_components( ~\Anaconda3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\initialization.py in initialize_components(Y, K, gSig, gSiz, ssub, tsub, nIter, maxIter, nb, kernel, use_hals, normalize_init, img, method, max_iter_snmf, alpha_snmf, sigma_smooth_snmf, perc_baseline_snmf, options_local_NMF, rolling_sum, rolling_length, sn, options_total, min_corr, min_pnr, ring_size_factor, center_psf, ssub_B, compute_B_3x, init_iter) 353 Y, Y_ds, max_number=K, gSiz=gSiz[0], gSig=gSig[0], min_corr=min_corr, min_pnr=min_pnr, 354 ring_size_factor=ring_size_factor, center_psf=center_psf, options=options_total, --> 355 sn=sn, nb=nb, ssub=ssub, ssub_B=ssub_B, compute_B_3x=compute_B_3x, init_iter=init_iter) 356 357 elif method == 'sparse_nmf': ~\Anaconda3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\initialization.py in greedyROI_corr(Y, Y_ds, max_number, gSiz, gSig, center_psf, min_corr, min_pnr, seed_method, min_pixel, bd, thresh_init, ring_size_factor, nb, options, sn, save_video, video_name, ssub, ssub_B, compute_B_3x, init_iter) 1019 print('Compute Background') 1020 W, b0 = compute_W(Y_ds.reshape((-1, total_frames), order='F'), -> 1021 A, C, (d1, d2), ring_size_factor * gSiz, ssub=ssub_B) 1022 1023 def compute_B(b0, W, B): # actually computes -B to efficiently compute Y-B in place ~\Anaconda3\envs\caiman\lib\site-packages\caiman\source_extraction\cnmf\initialization.py in compute_W(Y, A, C, dims, radius, data_fits_in_memory, ssub, tsub) 1637 downscale(A.reshape(dims + (-1,), order='F'), 1638 (ssub, ssub, 1)).reshape((-1, len(C)), order='F').dot( -> 1639 downscale(C, (1, tsub))) - \ 1640 downscale(b0.reshape(dims, order='F'), 1641 (ssub, ssub)).reshape((-1, 1), order='F') ValueError: cannot reshape array of size 0 into shape (0) Do you guys have any idea what the issue could be? Thank you, Xhoni
j-friedrich commented 6 years ago

Hi, you are likely using too high values for min_corr and/or min_pnr so that no neurons are found. Try reducing these values. Our code is hopefully soon, but not yet, robust to the case that a patch doesn't contain any neurons.

xhonial commented 6 years ago

Thank you very much for timely response! I have another situation with another computer where it gives me the same error, but with the demo dataset. Could it be an issue in installation?

Best, Xhoni

xhonial commented 6 years ago

Also I tried to make the min_corr and min_pnr values progressively smaller, but it kept giving me the same error.

j-friedrich commented 6 years ago

fixed it in master and dev. Both handle now the case that a patch doesn't contain any components