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
Pixel classification predictions using Ilastik classifier #13
Conversation
predict.py
Outdated
|
||
fin = tempfile.NamedTemporaryFile(suffix=".h5", delete=False) | ||
|
||
with h5py.File(fin.name, "w") as f: |
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.
Ilastik can use NumPy arrays. You could replace this HDF5 stuff with numpy.save
.
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.
NumPy is not compatible with all versions of Ilastik. It doesn't seem to be supported in the version I have, which is 1.0.2.
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.
Exactly, we have only added the numpy
load/save interface recently. The upside of using hdf5 is that ilastik might access the data faster and not load it all into RAM if the images get really big.
|
||
x_data = image.pixel_data | ||
|
||
fin = tempfile.NamedTemporaryFile(suffix=".h5", delete=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.
Use TemporaryFile
scopes, e.g. with TemporaryFile as temporary:
.
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 link has some more temporary best practices:
https://security.openstack.org/guidelines/dg_using-temporary-files-securely.html
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.
I've opted to use another pattern suggested by the article since the behavior is unspecified when one process tries to write to a file opened by another process.
@0x00b1 I'm ready for another review. :) |
6f480df
to
3724c8b
Compare
Can you add what the output settings within ilastik should be to the documentation (ie that the user should just leave them at h5, etc)? I definitely was wondering that now on my first attempt to use it. |
I am an idiot, see below, but preserved comment in case someone else runs into this in the future.
FWIW, calling
does produce output, along with the following logs
|
SO it turns out this didn't break, but my screwup is likely to happen to more than just me so it should also be preserved as part of the module help (with better wording of course) and also preferably explicitly caught as an exception- Some brightfield images (such as BBBC030) are actually RGB color but look grayscale. CP will happily load them if you set the as "Grayscale" in NamesAndTypes and will just collapse all the colors together (as is documented in NamesAndTypes), but then the error from my preceding comment will occur when you try to pass them to ilastik since ilastik is expecting an RGB color image. Changing the type to "Color" in NamesAndTypes fixes the error. |
I've tried the module with CP3.0.0rc7 but the right-hand-side image in CP output window is a blank image with Channel 1 values set to 1.0 and Channel 2 set to 0. The ilp project executed in the headless mode produces correct Probabilities.h5 file. Files for testing are here. |
Hi @dmattek -- I believe there is a fundamental problem with the module. CellProfiler implicitly rescales image data to the range [0.0, 1.0] on load, while ilastik does not implicitly rescale. Your image data is 16-bit unsigned integer, which means your classifier is trained on integer data in range [0, 65536) but asked to make predictions on floating point data in range [0.0, 1.0]. This is why we recommend a two-pipeline approach:
I tried this process on your images, and it worked. Could you please let me know if you are also successful? Of course, let me know if you still aren't getting the result you want. I will try to figure out a way to circumvent this dual pipeline approach since it's non-intuitive and annoying. |
Hi, again, @dmattek - I have a solution that is slightly better than running two CellProfiler pipelines. You can rescale your image back to its original data range using the ImageMath module: Settings to use:
I'll update the module documentation with this information. |
* Address how to handle rescaling by CellProfiler * Expand documentation for project types
I'm finding this only works for me when running from source, not compiled. Has anyone else observed this, and/or does anyone have an idea as to why? |
@bethac07 I am able to run a pipeline with this module using the latest released version of CellProfiler. What behavior are you observing? What version of CellProfiler are you using? |
In the 3.0.0 release version, in TestMode (or AnalysisMode after hitting cancel due to #19) I get a popup error (Forgive typos, I'm transcribing)
This leads to a console error:
In a relatively recent master (CellProfiler/CellProfiler@4e5dd74) it runs fine in TestMode; it just hangs indefinitely in analysis mode, as Kyle has previously noted (#19). Image and pipeline here. |
@bethac07 From the stack trace you posted it looks like this is an issue with Ilastik. Maybe there’s some compatibility issue between the version of H5Py that CellProfiler links and the version of H5Py that Ilastik links. |
Hi @bethac07, that error you posted looks weird. Does that ilastik installation usually work? We've finally released a beta version of ilastik 1.3.0 where we've fixed lots of bugs and upgraded all our dependencies (Python 3, Qt5, and lots more), giving ilastik a noticeable performance boost. @bethac07 would you mind trying the same thing with this new ilastik version? We'd love to see the bridge working again, and it's great how much effort you guys have put in there already! If the error persists with ilastik 1.3.0, let us know and we'll try to get it fixed! Cheers from Heidelberg |
@chaubold @mcquin @0x00b1 Using ilastik 1.3.0, I still get that same error in 3.0.0 built and still do NOT get it when running from 3.0.0 source (I even used the 3.0.0 release commit to try to be as parallel as possible). Naively it therefore seems to me that this is at least partly a CP error rather than an ilastik error, otherwise why the different behavior between prebuilt and source, but IANASE. Built:
Source
|
The last commit added support for 1-channel images, which could not be processed by ilastik (the hdf5 file stored the image data in the format (x_dim, y_dim) but ilastik expects (x_dim, y_dim, 1) ). @mcquin @0x00b1 in case of a 2 stage classifier the probabilities of stage 2 are exported / returned using |
Create probability maps using an Ilastik pixel classifier. Users must specify the Ilstik executable name, or provide the path to the executable if it is not on the system path. Additionally, users must specify the location of their project (.ilp) file.
Input:
Output:
Probability map segmentation with IdentifyPrimaryObjects:
@chaubold @stuarteberg @karhohs @bethac07 @0x00b1