clij / clijpy

GPU-accelerated image processing using CLIJ via pyimagej in python
https://clij.github.io/clijpy
BSD 3-Clause "New" or "Revised" License
10 stars 1 forks source link

clij in Google Colab #5

Closed erjel closed 4 years ago

erjel commented 4 years ago

Hi @haesleinhuepf

I really love your effort to make GPU computation accessible to the imagej community. I wondered whether google colab is suitable for image analysis tasks and can be used to share example sets of clijpy.

So I created a notebook which tries to reproduce the clijpy jupyter example notebook:

https://colab.research.google.com/drive/1zo7DZRDK5FJTfEj5gUe4iLl7V4_7r48T

In short: I managed to start clijpy in google colab!

However I noticed some issues with the example notebook and wondered whether this is google colab specific:

In the function clij_pull I had to replace:

numpy_image = numpy.zeros([buffer.getWidth(), buffer.getHeight(), buffer.getDepth()])

with

numpy_image = numpy.zeros(np.flip(labelled_without_edges.dimensions))

The line

np_arr_result = ij.py.rai_to_numpy(ij_img_result);

results in the error message:

AttributeError                            Traceback (most recent call last)
<ipython-input-15-33e056f20bff> in <module>()
      2 print("Img conversion");
      3 millis = getTime();
----> 4 np_arr_result = ij.py.rai_to_numpy(ij_img_result);
      5 print (getTime() - millis)

/usr/local/lib/python3.6/dist-packages/imagej/imagej.py in rai_to_numpy(self, rai)
    171             """
    172             result = self.new_numpy_image(rai)
--> 173             self._ij.op().run("copy.rai", self.to_java(result), rai)
    174             return result
    175 

AttributeError: 'net.imagej.ops.OpService' object has no attribute 'run'

For the first issue I will create a pull request. Do you have any ideas on the second issue? Is this a colab-specific problem and does it run in your environment properly?

Best,

Eric

haesleinhuepf commented 4 years ago

Hey @erjel,

wow! I'm impressed. Super cool. Thanks for your efforts!

Thanks for fixing this dimensions-issue. I also struggled here not too long ago. Btw. the clij_pull method is just a workaround for this issue also related to the second issue you mention. I will remove clij_pull from the examples in a later version. Just FYI.

Regarding the second issue: It is a known bug in pyimagej https://github.com/imagej/pyimagej/issues/57

@imagejan suggested to increase the pyjnius version:

for now, you should be able to work around the issue by pinning to pyjnius version 1.2.0, see kivy/pyjnius#465.

Would you mind trying this out?

Thaaaanks for your support! I'm not so much the python person so every helping hand here is very welcome! ❤️

Cheers, Robert

imagejan commented 4 years ago

@haesleinhuepf wrote:

@imagejan suggested to increase the pyjnius version

To be precise, I suggested to decrease the pinned version, as pyjnius-1.2.1 has the issue, but pinning to 1.2.0 works around it.

erjel commented 4 years ago

With the pinned version I had to change to JRE and JDK version from 8 to 11 and manually create a symlink such that pyimagej can find libjvm.so.

But now the example notebook works without any changes.

I updated the notebook accordingly.

@haesleinhuepf : I guess you can close #6

haesleinhuepf commented 4 years ago

Thanks a lot again @erjel for clijing google colab. Looking forward to see this evolving! :-)