DIAGNijmegen / pathology-hooknet-tls

MIT License
6 stars 0 forks source link

Errors during postprocessing #2

Open yann-rdgz opened 4 months ago

yann-rdgz commented 4 months ago

Thanks a lot for sharing and for your work !

I have 2 errors when predicting at the step of postprocessings:

  1. the first one is related to MultiPolygon object:

    polygons = list(p)
    TypeError: 'MultiPolygon' object is not iterable

    possible fix: in postprocessings.py > convert_polygons_to_annotations

    if isinstance(p, MultiPolygon):
                polygons = list(p.geoms)
  2. the other one is related to STRTree object:

    loading weights... /tmp/weights.h5
    Create output folder
    All output files already exist, skipping inference.
    writing json file: /output/images/filtered/TCGA-18-3406-01Z-00-DX1_hooknettls_tls_filtered.json
    Exception has occurred: AttributeError
    'numpy.int64' object has no attribute 'bounds'
    File "/home/user/pathology-hooknet-tls/hooknettls/__main__.py", line 8, in <module>
    objects = build_config(config_reader.read()["default"])
    AttributeError: 'numpy.int64' object has no attribute 'bounds'

possible fix: in postprocessings.py > in_tls

def in_tls(tls_tree, gc_annotation: Annotation):
    tls_indices: list[Annotation] = tls_tree.query(gc_annotation)
    tls_annotations = [tls_tree.geometries[indices] for indices in tls_indices]
    for tls_annotation in tls_annotations:
        tls_box = box(*tls_annotation.bounds)
        if (gc_annotation.intersection(tls_box).area / gc_annotation.area) >= 0.5:
            return True
    return False

FYI: I wanted to open a PR but I am not able to push a branch !

Thanks again for your this great work!

martvanrijthoven commented 4 months ago

Dear Yann,

Thank you for bringing this issue to my attention and suggesting a solution for the first error. I agree with your proposed fix and have implemented it. However, I'm hesitant about the second error due to some typing discrepancies I found in the original code.

I've updated the main branch with the fix for the first error and addressed the typing issues. You can view the changes here: https://github.com/DIAGNijmegen/pathology-hooknet-tls/commit/d2ff3c1182350ae22d849952290b8660dce78717.

Interestingly, I've previously processed TCGA-18-3406-01Z-00-DX1 without encountering these errors. Could you please review the updated code to see if the issues persist? Feel free to open a PR, by cloning the repo, create a new branch, and then submit the PR. If you encounter any issues, don't hesitate to let me know, and I'll look into it further.

Best wishes, Mart

yann-rdgz commented 4 months ago

Dear Mart, Thank you for the update ! 🙏 I will try and give you a feedback

About the second one, I look closely and it depends of the version of shapely:

I don't know why but I installed a different version of shapely! Maybe the query_geoms method can be used to query only geometry for all versions!

Best wishes, Yann

martvanrijthoven commented 4 months ago

Dear Yann,

Thank you so much for looking more closely to the second issue and finding the problem. I would say the algorithm should work at least with shapely2.0 (and preferably will all versions).

I will check your proposed solution and do some tests asap.

Thanks again for your input, very helpful!

Best wishes, Mart