uhlmanngroup / splinedist

SplineDist: Automated Cell Segmentation with Spline Curves
BSD 3-Clause "New" or "Revised" License
65 stars 15 forks source link

Visualising predictions in notebook after training throws error 'function takes exactly 6 arguments (7 given)' #2

Closed loicsauteur closed 2 years ago

loicsauteur commented 2 years ago

Hi

I know you still working on optimising everything, when I read about splinedist I wanted to try it out. Running your training notebook, I came across an error in the Visualization part: Cell: Y_val_pred = [model.predict_instances(x, n_tiles=model._guess_n_tiles(x), show_tile_progress=False)[0] for x in tqdm(X_val)] Error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_19908/2124612019.py in <module>
----> 1 Y_val_pred = [model.predict_instances(x, n_tiles=model._guess_n_tiles(x), show_tile_progress=False)[0]
      2               for x in tqdm(X_val)]

~\AppData\Local\Temp/ipykernel_19908/2124612019.py in <listcomp>(.0)
----> 1 Y_val_pred = [model.predict_instances(x, n_tiles=model._guess_n_tiles(x), show_tile_progress=False)[0]
      2               for x in tqdm(X_val)]

~\Downloads\splinedist-main\splinedist\models\base.py in predict_instances(self, img, axes, normalizer, prob_thresh, nms_thresh, n_tiles, show_tile_progress, verbose, predict_kwargs, nms_kwargs, overlap_label)
    444 
    445         prob, dist = self.predict(img, axes=axes, normalizer=normalizer, n_tiles=n_tiles, show_tile_progress=show_tile_progress, **predict_kwargs)
--> 446         return self._instances_from_prediction(_shape_inst, prob, dist, prob_thresh=prob_thresh, nms_thresh=nms_thresh, overlap_label=overlap_label, **nms_kwargs)
    447 
    448 

~\Downloads\splinedist-main\splinedist\models\model2d.py in _instances_from_prediction(self, img_shape, prob, dist, prob_thresh, nms_thresh, overlap_label, **nms_kwargs)
    396 
    397         coord = dist_to_coord(dist, grid=self.config.grid)
--> 398         inds = non_maximum_suppression(coord, prob, grid=self.config.grid,
    399                                        prob_thresh=prob_thresh, nms_thresh=nms_thresh, **nms_kwargs)
    400         labels = polygons_to_label(coord, prob, inds, shape=img_shape)

~\Downloads\splinedist-main\splinedist\nms.py in non_maximum_suppression(coord, prob, grid, b, nms_thresh, prob_thresh, verbose, max_bbox_search)
     60         t = time()
     61 
---> 62     survivors[ind] = c_non_max_suppression_inds(polygons.astype(np.int32),
     63                     mapping, np.float32(nms_thresh), np.int32(max_bbox_search),
     64                     np.int32(grid[0]), np.int32(grid[1]),np.int32(verbose))

TypeError: function takes exactly 6 arguments (7 given)

Probably you are aware and already working on it... Cheers

[Edit]: maybe I messed up the installation... which I did on top of stardist environment and the help some code found in the notebook from ZeroCostDL4Mic. And I use my own data.

saskra commented 2 years ago

I get the exact same error message and I have not made any changes to code or data. A possible source of error could perhaps be the installed versions of the Python packages. Could you provide a requirements.txt and/or environment.yml to test it again? I could upload my versions of it here if it would be interesting for comparison.

loicsauteur commented 2 years ago

My impression is that there is something wrong with the splinedist function non_maximum_suppression and its call during the visualisation part of the training notebook and also for the prediction notebook. For you try the requirements.txt and environment.yml (as txt) from my env.

splinedist_requirements.txt

splinedist.yml.txt

Good luck and let me know if you find something.

saskra commented 2 years ago

Thanks for this! I'm just afraid that this is not directly comparable because you use Windows and I use Ubuntu Linux. (In fact, I don't see any indication on which operating systems Splinedist has been tested by its creators). Nevertheless, attached are my corresponding files, even though those of the original authors would of course be much more interesting. At least we can see that we have already tested two different versions of Tensorflow and Stardist, among others, and that they all came up with the same error.

requirements.txt

loicsauteur commented 2 years ago

Hi @saskra, I got it to work on my Windows machine. Sorry for not sharing the requirement.txt file. Here what I installed in a fresh environment:

First, create a anaconda python 3.7 env, install git (done via anaconda UI) and start a cmd. Second, cd to the working folder (i.e. where your data will be, running trainings etc. It will require the splinedist cloned directory folder present there).

Install following stuff:

pip install --upgrade numpy
pip install tifffile
pip install tensorflow
pip install csbdeep
pip install -e git://github.com/stardist/stardist.git@0.6.2#egg=stardist

→ install pyopencl _This is machine dependent. In my case (for windows): download a wheel (for the Win version and matching python version) to your current working directory: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl and use e.g.: pip install "pyopencl-2021.2.9+cl21-cp37-cp37m-win_amd64.whl"_

pip install gputools
pip install edt
pip install wget
pip install fpdf
pip install PTable
git clone https://github.com/uhlmanngroup/splinedist

→ to make sure that jupyter is using the proper python environment (or kernel): conda install -c conda-forge notebook

pip install packaging cd to splinedist folder

python setup.py install
python splinegenerator.py install

correct the numpy version (nube needs numpy<=1.20) if you get a warning - This may be OS dependent pip install numpy==1.20

The following dependencies are probably more for running the notebooks provided by ZeroCostDL4Mic, but wont hurt installing...

pip install opencv-python
pip install pandas
pip install sklearn
pip install astropy
pip install ipywidgets
pip install tabulate

Generally I run into the problem that for prediction it did not find the phi_16.npy and grid_16.npy files. I could overcome that by coping those files (from the model folder) to the current working diretory.

sohmandal commented 2 years ago

Hello @loicsauteur, hello @saskra, thank you for your interest in SplineDist. My apologies for the late response on this issue. You have been absolutely right, the issue has been due to the incompatibility of the current version of SplineDist with the new versions of the StarDist package. In a fresh environment, could you please pip install stardist==0.6.2, and then try SplineDist. I have updated the readme now mentioning the same solution. Please let me know if this does not sort out the issue.

saskra commented 2 years ago

Thank you, that was the solution to this error!

However, I now have the next problem: If I install Stardist via pip and Tensorflow via Conda, then again something does not seem to match from the versions. However, when I install Tensorflow via pip, I am missing packages like cudatoolkit, cudnn and cupti, which are not available with pip. Unfortunately I can't change their permanently installed variants on the server, so I would like to install them only locally in the conda environment. So a complete requirements.txt or environment.yml including the version numbers of tensorflow etc. would be helpful for me.

sohmandal commented 2 years ago

Here is the environment.yml file. Hope this helps.

environment.yml.txt

saskra commented 2 years ago

Thanks, that works!

sohmandal commented 2 years ago

Closing this issue now. Please feel free to reopen it, if the issue is still not solved.