kbressem / trainlib

MIT License
4 stars 0 forks source link

Enable 2d Segmentation #68

Closed kbressem closed 1 year ago

kbressem commented 1 year ago

Summary

This PR adds support for 2d segmentation.

Enhanced viewing

Enhances the interactive viewer to support 2D and 3D data. The viewer can display grayscale images (standard cmap is "bone"), 2D RGB images (mode = "RGB" when viewer is initialized), and greyscale 3D images. As labels (y) an array (torch.Tensor, np.ndarray, a string or a number is supported). Additionally, a prediction can be provided alongside the label to visualize correct/wrong examples. An optional description (string) can also be added to each plot.

All three viewers (BasicViewer, DicomExplorer and ListViewer) support the new functionalities.

image

In the above image "A Chest X-Ray", "Another X-Ray", "A CT", "Another CT" are file descriptions passed manually. Useful for sharing code (or adding the filename). "There is Pneumonia" and "There is Covid" are labels passed as y to the viewer.

Multiple tests for the viewers have been added as well.

2d support for show_batch

Show batch can now display 2d, 2d RGB and 3d data. Multichannel data (2d or 3d) is split into single instances and the label is duplicated across all instances

Increase speed of show_batch

show_batch is now more than 10 times faster. In the previous implementation, each time a batch was drawn, the data loader first spawned multiple subprocesses, which took considerable time. Now only one data item is drawn, making the function much faster. The larger the transforms pipeline, the more noticeable this should be.

Add new test data

Three new 2d images and corresponding labels were added. On purpose, I have made them in different formats (nrrd, nii.gz, png).

2d segmentation

SegmentationTrainer now accepts 2d data as input. Config can remain largely unchanged for this.

Preparations for classification functionalities

I already started preparations for #41:

kbressem commented 1 year ago

Ok ... this got a bit out of hand yesterday. I decided to test 2d segmentation on another project first and ran into multiple errors which lead to many changes in the library. However, these changes are not necessarily relevant to 2d. As short summary: