Can we programatically extract % of each class from .hdf5 output file? #92
Replies: 2 comments 6 replies
-
Hello, @lomshabhishek! :] NOTE: Next time I recommend making a Q/A instead of a General post, as we can assign solution to the original question. Regarding your question, you can do that from python. In FP, you should have created a project, added an image to the project, and ran the BACH model, right? In that case, the generated HDF5 file should lie in the project. Given the path of the HDF5 file, you can then read it by:
The tensor should be an image with four channels. I then argmaxed it across the channel dimension which should assign one class to each pixel. I then return the class frequency. If you are cool, you could also just calculate the percentage directly using:
Just note that most of that image will be empty (zero value), as most of the image will be glass. In that case, if one of your classes is assigned to 0, which is a non-glass class, this class frequency will be overestimated, as both the class of interest and background will be included in this count. So if you want to only calculate the percentage based on tissue, you will first need to get the tissue image, and then remove it from the BACH image by doing something like:
The tissue image you can save in the project and load it. You might need to resize it to match the heatmap (HDF5) output. When resizing remember to use nearest neighbour to avoid any funny business. Maybe this is enough for you to get started. Let me know if you have any other issues :] |
Beta Was this translation helpful? Give feedback.
-
@smistad Isn't this a very natural feature people would be interested in seeing when running a WSI-classifier using a patch-wise classifier, or just a patch-wise classifier for segmentation in general? Adding support for this for pw-classifiers (heatmaps) should be a lot easier than for semantic segmentation models. If we are able to accumulate as the pw-classifier runs to build up a histogram, when it is finished, it could be something that is returned. In FP, we could save this histogram on disk in CSV format, or even easier, as part of the already existing HDF5 similar to I believe we played around with adding support for qwt or something similar. It might even been added support for building FAST with said library, but I am not sure this was ever tested. I do not really recall atm which it was. Do you, @smistad? IMO, the ideal library would be Shall I make a feature request under issues in FP? |
Beta Was this translation helpful? Give feedback.
-
I ran BACH classifier and was wondering if we can programmatically extract % of each class from the .hdf5 generated by the fastpathology desktop app
Beta Was this translation helpful? Give feedback.
All reactions