-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pims fallback for avi loading #1161
Conversation
…for avi files) to the one that load() has
…separate function so we don't repeat it
… CAP_DSHOW in opencv - doesn't actually work as a workaround
Dev load pims fallback
…xtra sanity-checks. Remove some more tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generally looks good. Solid debugging/fixup work!
caiman/base/movies.py
Outdated
@@ -1331,7 +1331,7 @@ def load(file_name: Union[str, List[str]], | |||
is3D=is3D) | |||
|
|||
elif isinstance(file_name, tuple): | |||
print(f'**** Processing input file {file_name} as individualframes *****') | |||
logging.debug(f'**** Processing input file {file_name} as individualframes *****') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good time to stick a space between individual and frames
caiman/base/movies.py
Outdated
# Instead we'll explicitly go with the DirectShow backend on Windows, which | ||
# seems to have good broad codec support (if this turns out to break other users, | ||
# we may need a more complex solution) | ||
# We first try with OpenCV, which is very dependent on having a working backend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I stick the word "very" in there? If I did, my bad. Shouldn't be there.
dims[ind] = sb.shape[0] | ||
|
||
start_frame = subindices[0][0] | ||
if length <= 0 or width <= 0 or height <= 0: # OpenCV failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to do it here (not really a comment for review, per se) but I eventually intend to pull this check out into a separate function because we do it a few times in a few places
caiman/base/movies.py
Outdated
def rgb2gray(rgb): | ||
return np.dot(rgb[..., :3], [0.299, 0.587, 0.114]) | ||
|
||
# When everything done, release the capture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When everything is done
caiman/base/movies.py
Outdated
input_arr = np.zeros((dims[0], height, width), dtype=np.uint8) | ||
for i, ind in enumerate(subindices[0]): | ||
input_arr[i] = rgb2gray(pims_movie[ind]).astype(outtype) | ||
# logging.debug(f"subindex and shape: {ind} {input_arr[i].shape}") # helpful when mc debugging deep in weeds, otherwise overkill |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove before commit?
caiman/base/movies.py
Outdated
@@ -1982,7 +2026,7 @@ def from_zip_file_to_movie(zipfile_name: str, start_end: Tuple = None) -> Any: | |||
mov[counter] = np.array(Image.open(file)) | |||
|
|||
if counter % 100 == 0: | |||
print([counter, idx]) | |||
logging.debug([counter, idx]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clean this up a bit (not your fault, but since we're touching it); passing raw arrays to printing function means they're going to show up raw and ugly.
caiman/base/movies.py
Outdated
1 if subindices.step is None else subindices.step) | ||
t = 0 | ||
for ind in subindices: | ||
# an abomination reading frames until it hits the desired frame |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we want to use this wording
caiman/base/movies.py
Outdated
1 if subindices.step is None else subindices.step) | ||
for ind in subindices: | ||
frame = rgb2gray(pims_movie[ind]) | ||
# debug.logging(f"t, ind and frame shape: {ind} - {frame.shape}") # for extremely in the weeds debugging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to leave this in?
@@ -78,7 +107,7 @@ | |||
"source": [ | |||
"# motion correction parameters\n", | |||
"motion_correct = True # flag for performing motion correction\n", | |||
"pw_rigid = False # flag for performing piecewise-rigid motion correction (otherwise just rigid)\n", | |||
"pw_rigid = True # flag for performing piecewise-rigid motion correction (otherwise just rigid)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to change this (and in this diff) or was this just for debugging??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good eye that was for debugging. I'll switch it back
@@ -336,7 +391,7 @@ | |||
"gSig = (10//ds_factor, 10//ds_factor) # expected half size of neurons\n", | |||
"gSiz = (22//ds_factor, 22//ds_factor)\n", | |||
"sniper_mode = False # flag using a CNN to detect new neurons (o/w space correlation is used)\n", | |||
"init_batch = 300 # number of frames for initialization (presumably from the first file)\n", | |||
"init_batch = 200 # number of frames for initialization (presumably from the first file)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with these other notebook changes
@@ -291,7 +348,7 @@ | |||
"metadata": {}, | |||
"outputs": [], | |||
"source": [ | |||
"cnm.estimates.play_movie(images, magnification=0.75, include_bck=False)" | |||
"cnm.estimates.play_movie(images, magnification=0.75, include_bck=False);" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
semicolons are a bit unusual in python
caiman/motion_correction.py
Outdated
@@ -3076,6 +3076,9 @@ def tile_and_correct_wrapper(params): | |||
extension = extension.lower() | |||
shift_info = [] | |||
|
|||
print("In tile and correct wrapper about to call load with subidxs") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These messages are noisy when run in the notebook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Cutting errant debugging msg.
" magnification=1,\n", | ||
" gain=0.6,\n", | ||
" plot_text=True,\n", | ||
" do_loop=True)\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we're going to default to looping, we should tell the user that they shouldn't keep waiting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point I'll cut that.
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Inspect the summary images so you can set parameters in the following section." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cell was not commited pre-run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was not executed, I mean
@@ -251,6 +301,15 @@ | |||
"t1 += time()" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more clever than it is legible
Description
This should fix the problems with loading avi in Windows. It cleans up the logic of the pims fallback branch (thanks Pat), and I worked on the subindixing bits in pims, which was also neglected. Main change is fix to
caiman_.base.movies.load()
and.load_iter()
methods (the later is used in online methods)Fixes #1137 #883
Type of change
Introduces no new problems with tests.
Ran tests in pims_load_testing.py
Now the cnmfe online demo notebook runs (
demo_online_cnmfE.ipynb
). It would be good if someone tests on linux/mac.