schnitzer-lab / EXTRACT-public

EXTRACT is a tractable and robust automated cell extraction tool for calcium imaging, which extracts the activities of cells as time series from both one-photon and two-photon calcium imaging movies.
MIT License
64 stars 17 forks source link

"Incorrect dimensions for matrix multiplication." Error #21

Closed kimtonyhyun closed 2 years ago

kimtonyhyun commented 2 years ago

Hi @fatihdinc,

I recently refreshed my local copy of EXTRACT-public. When running EXTRACT the same way as I have in the past, I'm encountering the following error:

31-May-2022 10:30:53: Running EXTRACT on "mCN02-0404-s07-1P_mc_cr_norm40_dff_ti4.hdf5"...
31-May-2022 10:30:53: Getting GPU information... 
             GPU Device 1 - NVIDIA GeForce RTX 2070: Available Memory: 6.9 Gb
             - Selecting GPU device 1 
31-May-2022 10:30:56: Signal extraction on partition 16 (of 16):
             Uploading the movie... 
Warning: The baseline values for the pre-processed movie are missing, assuming the movie is dfofed... 
             Using the provided pre-processed movie...
             Finding cells with component-wise EXTRACT...
                 noise std: 0.0106 
                 minimum magnitude: 0.0040 
             4 cells found after a total of 21 steps. 
             Updating S and T with alternating estimation...
             End of iter # 1: # cells: 2 (2 removed) 
             End of iter # 2: # cells: 0 (2 removed) 
             Zero cells, stopping. 
             Providing baseline adjusted traces with adaptive kappa... 
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches
the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in run_extract (line 848)
F_per_cell = S_prob' * config.F_per_pixel(:);
Error in extractor (line 368)
        [S_this, T_this, summary_this] = run_extract(M_small, config_this);
Error in preproc_1p2p (line 124)
output = extractor(sprintf('%s:/Data/Images', movie_filename), config);

I wonder if this has to do with the fact that there are 0 candidate sources in the partition/tile currently being worked on? Can you please advise?

fatihdinc commented 2 years ago

Thanks Tony, this is a nice catch. It should be fixed right now, could you update your version, try again and let me know? This was due to the fact that while we stop the cell refinement when no cells are found, we were not stopping final robust regression. Now we do!

fatihdinc commented 2 years ago

Alternatively, you can update the following part in run_extract.m

if isempty(T)
    str = sprintf('\t \t \t Zero cells, stopping. \n');
    script_log = [script_log, str];
    dispfun(str, config.verbose ==2);
    break;
end

with this:

if isempty(T)
    str = sprintf('\t \t \t Zero cells, stopping. \n');
    script_log = [script_log, str];
    dispfun(str, config.verbose ==2);
    config.trace_output_option = 'none';
    config.reestimate_T_if_downsampled = 0;
    break;
end
kimtonyhyun commented 2 years ago

I sync'ed my local copy just now, and will report back once the run completes.

kimtonyhyun commented 2 years ago

After syncing the repo, and confirming your changes in run_extract.m, I still got the same error:

31-May-2022 10:50:28: Running EXTRACT on "mCN02-0404-s07-1P_mc_cr_norm40_dff_ti4.hdf5"...
31-May-2022 10:50:28: Getting GPU information... 
             GPU Device 1 - NVIDIA GeForce RTX 2070: Available Memory: 6.9 Gb
             - Selecting GPU device 1 
31-May-2022 10:50:30: Signal extraction on partition 16 (of 16):
             Uploading the movie... 
Warning: The baseline values for the pre-processed movie are missing, assuming the movie is dfofed... 
             Using the provided pre-processed movie...
             Finding cells with component-wise EXTRACT...
                 noise std: 0.0106 
                 minimum magnitude: 0.0040 
             4 cells found after a total of 21 steps. 
             Updating S and T with alternating estimation...
             End of iter # 1: # cells: 2 (2 removed) 
             End of iter # 2: # cells: 0 (2 removed) 
             Zero cells, stopping. 
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches
the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.
Error in run_extract (line 850)
F_per_cell = S_prob' * config.F_per_pixel(:);
Error in extractor (line 368)
        [S_this, T_this, summary_this] = run_extract(M_small, config_this);
Error in preproc_1p2p (line 124)
output = extractor(sprintf('%s:/Data/Images', movie_filename), config);
fatihdinc commented 2 years ago

That's weird. I can see where it happens, but I am not reproducing the same error in my MATLAB in the same situation. Could you remind me which MATLAB version you are running?

fatihdinc commented 2 years ago

Anyways, it should be fixed now with my recent commits. Please let me know if it is not. In any case, thank you for catching this, this was very helpful!

kimtonyhyun commented 2 years ago

I sync'ed just now, and I'm still seeing a similar problem:

31-May-2022 12:45:24: Running EXTRACT on "mCN02-0404-s07-1P_mc_cr_norm40_dff_ti4.hdf5"...
31-May-2022 12:45:25: Getting GPU information... 
             GPU Device 1 - NVIDIA GeForce RTX 2070: Available Memory: 6.9 Gb
             - Selecting GPU device 1 
31-May-2022 12:45:27: Signal extraction on partition 16 (of 16):
             Uploading the movie... 
Warning: The baseline values for the pre-processed movie are missing, assuming the movie is dfofed... 
             Using the provided pre-processed movie...
             Finding cells with component-wise EXTRACT...
                 noise std: 0.0106 
                 minimum magnitude: 0.0040 
             4 cells found after a total of 21 steps. 
             Updating S and T with alternating estimation...
             End of iter # 1: # cells: 2 (2 removed) 
             End of iter # 2: # cells: 0 (2 removed) 
             Zero cells, stopping. 
             Count: 0 cells.
Unable to perform assignment because the left and right sides have a different number of elements.
Error in extractor (line 383)
            F_per_pixel(fov_occupation(:)) = summary_this.config.F_per_pixel(:);
Error in preproc_1p2p (line 124)
output = extractor(sprintf('%s:/Data/Images', movie_filename), config);

Btw I'm using 2019b.

fatihdinc commented 2 years ago

Would you like to send me the movie and the script you use? Somehow, you are probably not getting F_per_pixel inside the config file but that does not make sense at all…

On May 31, 2022, at 12:47 PM, Tony @.**@.>> wrote:

I sync'ed just now, and I'm still seeing the same problem:

31-May-2022 12:45:24: Running EXTRACT on "mCN02-0404-s07-1P_mc_cr_norm40_dff_ti4.hdf5"... 31-May-2022 12:45:25: Getting GPU information... GPU Device 1 - NVIDIA GeForce RTX 2070: Available Memory: 6.9 Gb

— Reply to this email directly, view it on GitHubhttps://github.com/schnitzer-lab/EXTRACT-public/issues/21#issuecomment-1142576903, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANNMFC3QBLF7SSPRLG7IZQ3VMZUEPANCNFSM5XOKGWIA. You are receiving this because you were mentioned.Message ID: @.***>

kimtonyhyun commented 2 years ago

Hi Fatih,

I'll send you the link to the movie privately. As for my EXTRACT script, here it is:

movie_filename = get_most_recent_file('', '*.hdf5');
cprintf('Blue', '%s: Running EXTRACT on "%s"...\n', datestr(now), movie_filename);

config = get_defaults([]);
config.preprocess = 0;
config.remove_stationary_baseline = 0;
config.cellfind_filter_type = 'none';
config.cellfind_min_snr = 0;

switch dirname
    case '1P'
        config.num_partitions_x = 4;
        config.num_partitions_y = 4;
        config.avg_cell_radius = 5;

    otherwise % Assume 2P
        config.num_partitions_x = 1;
        config.num_partitions_y = 1;
        config.avg_cell_radius = 10;
end

output = extractor(sprintf('%s:/Data/Images', movie_filename), config);
cprintf('Blue', 'Done with EXTRACT. Found %d cells in %.1f min\n',...
    size(output.spatial_weights, 3), output.info.runtime / 60);

(For this movie, I'm using the '1P' config settings.)

fatihdinc commented 2 years ago

Hi Tony,

The error is now fixed. I see the issue now, thank you so much for your contribution. I think I fixed 2 separate bugs today, one intentionally one unintentionally :) I will work giving you a good set of parameters now!

On May 31, 2022, at 1:02 PM, Tony @.**@.>> wrote:

Hi Fatih,

I'll send you the link to the movie privately. As for my EXTRACT script, here it is:

movie_filename = get_most_recent_file('', '*.hdf5'); cprintf('Blue', '%s: Running EXTRACT on "%s"...\n', datestr(now), movie_filename);

config = get_defaults([]); config.preprocess = 0; config.remove_stationary_baseline = 0; config.cellfind_filter_type = 'none'; config.cellfind_min_snr = 0;

switch dirname case '1P' config.num_partitions_x = 4; config.num_partitions_y = 4; config.avg_cell_radius = 5;

otherwise % Assume 2P
    config.num_partitions_x = 1;
    config.num_partitions_y = 1;
    config.avg_cell_radius = 10;

end

output = extractor(sprintf('%s:/Data/Images', movie_filename), config); cprintf('Blue', 'Done with EXTRACT. Found %d cells in %.1f min\n',... size(output.spatial_weights, 3), output.info.runtime / 60);

(For this movie, I'm using the '1P' config settings.)

— Reply to this email directly, view it on GitHubhttps://github.com/schnitzer-lab/EXTRACT-public/issues/21#issuecomment-1142588834, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ANNMFC6C2KMKANT76WKCMCDVMZV57ANCNFSM5XOKGWIA. You are receiving this because you were mentioned.Message ID: @.***>

kimtonyhyun commented 2 years ago

Hi Fatih,

With the latest changes, EXTRACT runs to completion on this movie without error. Closing issue,

-Tony

kimtonyhyun commented 2 years ago

I’m using either 2019a or b (not in front of my computer at the moment),

-Tony (from phone)

On May 31, 2022, at 11:02 AM, Fatih Dinc @.***> wrote:

 That's weird. I can see where it happens, but I am not reproducing the same error in my MATLAB in the same situation. Could you remind me which MATLAB version you are running?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.