SegSummarizer serializes the operations for data analysis in Auto3Dseg pipeline. It loads two types of analyzer functions and execute differently. The first type of analyzer is CaseAnalyzer which is similar to traditional monai transforms. It can be composed with other transforms to
| 32 | |
| 33 | |
| 34 | class SegSummarizer(Compose): |
| 35 | """ |
| 36 | SegSummarizer serializes the operations for data analysis in Auto3Dseg pipeline. It loads |
| 37 | two types of analyzer functions and execute differently. The first type of analyzer is |
| 38 | CaseAnalyzer which is similar to traditional monai transforms. It can be composed with other |
| 39 | transforms to process the data dict which has image/label keys. The second type of analyzer |
| 40 | is SummaryAnalyzer which works only on a list of dictionary. Each dictionary is the output |
| 41 | of the case analyzers on a single dataset. |
| 42 | |
| 43 | Args: |
| 44 | image_key: a string that user specify for the image. The DataAnalyzer will look it up in the |
| 45 | datalist to locate the image files of the dataset. |
| 46 | label_key: a string that user specify for the label. The DataAnalyzer will look it up in the |
| 47 | datalist to locate the label files of the dataset. If label_key is None, the DataAnalyzer |
| 48 | will skip looking for labels and all label-related operations. |
| 49 | do_ccp: apply the connected component algorithm to process the labels/images. |
| 50 | hist_bins: list of positive integers (one for each channel) for setting the number of bins used to |
| 51 | compute the histogram. Defaults to [100]. |
| 52 | hist_range: list of lists of two floats (one for each channel) setting the intensity range to |
| 53 | compute the histogram. Defaults to [-500, 500]. |
| 54 | histogram_only: whether to only compute histograms. Defaults to False. |
| 55 | |
| 56 | Examples: |
| 57 | .. code-block:: python |
| 58 | |
| 59 | # imports |
| 60 | |
| 61 | summarizer = SegSummarizer("image", "label") |
| 62 | transform_list = [ |
| 63 | LoadImaged(keys=keys), |
| 64 | EnsureChannelFirstd(keys=keys), # this creates label to be (1,H,W,D) |
| 65 | ToDeviced(keys=keys, device=device, non_blocking=True), |
| 66 | Orientationd(keys=keys, axcodes="RAS"), |
| 67 | EnsureTyped(keys=keys, data_type="tensor"), |
| 68 | Lambdad(keys="label", func=lambda x: torch.argmax(x, dim=0, keepdim=True) if x.shape[0] > 1 else x), |
| 69 | SqueezeDimd(keys=["label"], dim=0), |
| 70 | summarizer, |
| 71 | ] |
| 72 | ... |
| 73 | # skip some steps to set up data loader |
| 74 | dataset = data.DataLoader(ds, batch_size=1, shuffle=False, num_workers=n_workers, collate_fn=no_collation) |
| 75 | transform = Compose(transform_list) |
| 76 | stats = [] |
| 77 | for batch_data in dataset: |
| 78 | d = transform(batch_data[0]) |
| 79 | stats.append(d) |
| 80 | report = summarizer.summarize(stats) |
| 81 | """ |
| 82 | |
| 83 | def __init__( |
| 84 | self, |
| 85 | image_key: str, |
| 86 | label_key: str | None, |
| 87 | average: bool = True, |
| 88 | do_ccp: bool = True, |
| 89 | hist_bins: list[int] | int | None = None, |
| 90 | hist_range: list | None = None, |
| 91 | histogram_only: bool = False, |
no outgoing calls
searching dependent graphs…