Skip to content
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

the demo has something wrong #7

Closed
zimo-k opened this issue Apr 6, 2022 · 8 comments
Closed

the demo has something wrong #7

zimo-k opened this issue Apr 6, 2022 · 8 comments

Comments

@zimo-k
Copy link

zimo-k commented Apr 6, 2022

when I run the demo of demo_train_CNN_params.py
the code stop at the last step (parameter optimization)
but there are no error message in the terminal
the file of output mask and temp are always empty
May I ask you the cause of this problem?

@stepupdy
Copy link

when I run the demo demo_pipeline_1to3.bat, it seems that an error occurs at running demo_train_CNN_params_1to3.py

multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "D:\Anaconda3\envs\suns\lib\multiprocessing\pool.py", line 121, in worker
result = (True, func(*args, **kwds))
File "D:\Anaconda3\envs\suns\lib\multiprocessing\pool.py", line 47, in starmapstar
return list(itertools.starmap(args[0], args[1]))
File "../..\suns\PostProcessing\seperate_neurons.py", line 219, in separate_neuron
nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(thresh1, connectivity=4)
cv2.error: Unknown C++ exception from OpenCV code
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "demo_train_CNN_params_1to3.py", line 212, in
batch_size_eval, useWT=useWT, useMP=useMP, load_exist=load_exist)
File "../..\suns\train_CNN_params.py", line 330, in parameter_optimization_cross_validation
file_CNN, network_input, (Lx,Ly), Params_set, filename_GT, batch_size_eval, useWT=useWT, useMP=useMP, p=p)
File "../..\suns\train_CNN_params.py", line 197, in parameter_optimization_pipeline
list_Recall, list_Precision, list_F1 = parameter_optimization(pmaps, Params_set, filename_GT, useMP=useMP, useWT=useWT, p=p)
File "../..\suns\PostProcessing\complete_post.py", line 341, in parameter_optimization
segs = p.starmap(separate_neuron, [(frame, thresh_pmap, minArea, 0, False) for frame in pmaps], chunksize=1)
File "D:\Anaconda3\envs\suns\lib\multiprocessing\pool.py", line 276, in starmap
return self._map_async(func, iterable, starmapstar, chunksize).get()
File "D:\Anaconda3\envs\suns\lib\multiprocessing\pool.py", line 657, in get
raise self._value
cv2.error: Unknown C++ exception from OpenCV code

could you help me with this problem?

@YijunBao
Copy link
Owner

cv2.error: Unknown C++ exception from OpenCV code

I have not seen this error message before, and this error message is quite general. I have no idea of what caused it. Perhaps you can try to find out the problem by debugging. First, set useMP = False in demo_train_CNN_params_1to3.py to disable multiprocessing. Then run demo_train_CNN_params_1to3.py in debug mode, and ask your python IDE to pause on error. Then the program should pause immediately before the error line

line 219, in separate_neuron
nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(thresh1, connectivity=4)

Then you can check the function (cv2.connectedComponentsWithStats) and input (thresh1) to see if they are problematic. The thresh1 should be a binary image with the same size of movie frame, and most of the ones are pixels of neurons.

@dghauri0
Copy link

I've been having the same issue. thresh1 is converted to type uint8 in line 216 of seperate_neurons.py:
thresh1 = thresh1.astype('uint8') # Convert the binary image to uint8

I tried commenting this out to leave thresh1 as a binary image but the same error came up. OpenCV version installed is now 4.5.5 through environment creation. I was wondering what OpenCV version you used @YijunBao when creating this? Any other direction for a solution?

@YijunBao
Copy link
Owner

My opencv version is 3.4.1. The thresh1 should be converted to uint8 for some reason I forgot, but the values are still either 1 or 0. Are you able to pause debugging before the error line as I suggested in the previous comment? When use pause on error, you should be able to see what thresh1 is. Another direction is you can run cv2.connectedComponentsWithStats directly in aother python program, and see if it can work as expected.

@dghauri0
Copy link

dghauri0 commented Jun 17, 2022

Yep, the OpenCV version was the issue. In my case, I ended up using 3.4.2 since it was the first I saw compatible with python 3.7 in conda-forge prior to reading this message, but I'm sure 3.4.1 would've worked too. Thanks for the help.

I also had to change some restrictions in the dependencies in environment_suns.yml to prevent a bunch of package conflicts (for fissa and h5py). Since fissa version was changed, I did not copy over the core.py and neuropil.py in the installation directory as that was causing issues -- but that may be something else (or may be resolved by simply using 3.4.1). I've pasted that yml config below for anyone else having the same issue.

name: suns
channels:
  - conda-forge
  - defaults
dependencies:
  - python=3.7.8
  - pip
  - numpy
  - h5py    #=2.10.0
  - matplotlib
  - numba
  - opencv=3.4.2
  - scikit-image
  - scikit-learn
  - scipy
  - shapely 
  # - tensorflow==1.15
  - tensorflow-gpu==1.15
  - keras
  - pip:
    - fissa #==0.7.2
    - pyfftw
    - tensorflow-estimator==1.15.1
    - py-cpuinfo

@YijunBao
Copy link
Owner

Thank you very much for your information and update, @DG1038286. Version compatibility is indeed an issue for the code developped years ago. We have also seen same issue for h5py, and that is why the h5py version is specified in the environment_suns.yml. To reduce similar issues in the future, I provided environment_suns_fix_version.yml with all versions specified as the versions in my computer. This file can be used instead of environment_suns.yml, or as a reference for sovling version compatibility issues.
For fissa, yes, my changes are specific to v 0.7.2, so the core.py and neuropil.py cannot be used in newer version. These files aims to solve two problems in fissa v 0.7.2: redundant separate or separation_prep rerunning and limited video size to <4 GB. I see the first problem was solved in fissa v 1.0.0, but the second problem was not mentioned so far. I have not installed newer versions of fissa, so I would keep fissa == 0.7.2 in my yml file, but if the v 1.0.0 runs fine in your computer, that is a good news.

@YijunBao YijunBao closed this as completed Sep 7, 2022
@YijunBao YijunBao reopened this Sep 7, 2022
@YijunBao
Copy link
Owner

YijunBao commented Sep 7, 2022

when I run the demo of demo_train_CNN_params.py the code stop at the last step (parameter optimization) but there are no error message in the terminal the file of output mask and temp are always empty May I ask you the cause of this problem?

Sorry, I did not realize your initial question was different from the following discussions. How does the terminal look like when you define as "stop"? Does the code still utilize CPU even if the terminal does not update? If so, a possible reason is that it takes too much time in parameter optimization, so you see no progress in the terminal. You can change the ranges of the post-processing parameters you try to optimize (e.g., list_minArea, list_avgArea, list_thresh_pmap, and list_thresh_COM), as well as other fixed parameters (e.g., list_avgArea and thresh_COM0). Particularly, try increasing the lower bounds of list_minArea and list_thresh_pmap, because low minArea and low thresh_pmap can cause long post-processing time with poor results.

@zimo-k
Copy link
Author

zimo-k commented Sep 7, 2022

Thanks a lot for reading my question in detail. I have solve the problem with the following discussions. When I use opencv-python==3.4.2.17 ,the demo can correctly run very fast and have a fantastic result.

@YijunBao YijunBao closed this as completed Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants