MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __init__

Method __init__

monai/transforms/post/dictionary.py:949–999  ·  view source on GitHub ↗

Args: keys: keys of the corresponding items to model output, this transform only supports 1 key. See also: :py:class:`monai.transforms.compose.MapTransform` meta_keys: explicitly indicate the key of the corresponding metadata dictionary.

(
        self,
        keys: KeysCollection,
        meta_keys: KeysCollection | None = None,
        meta_key_postfix: str = DEFAULT_POST_FIX,
        saver: CSVSaver | None = None,
        output_dir: PathLike = "./",
        filename: str = "predictions.csv",
        delimiter: str = ",",
        overwrite: bool = True,
        flush: bool = True,
        allow_missing_keys: bool = False,
    )

Source from the content-addressed store, hash-verified

947 """
948
949 def __init__(
950 self,
951 keys: KeysCollection,
952 meta_keys: KeysCollection | None = None,
953 meta_key_postfix: str = DEFAULT_POST_FIX,
954 saver: CSVSaver | None = None,
955 output_dir: PathLike = "./",
956 filename: str = "predictions.csv",
957 delimiter: str = ",",
958 overwrite: bool = True,
959 flush: bool = True,
960 allow_missing_keys: bool = False,
961 ) -> None:
962 """
963 Args:
964 keys: keys of the corresponding items to model output, this transform only supports 1 key.
965 See also: :py:class:`monai.transforms.compose.MapTransform`
966 meta_keys: explicitly indicate the key of the corresponding metadata dictionary.
967 for example, for data with key `image`, the metadata by default is in `image_meta_dict`.
968 the metadata is a dictionary object which contains: filename, original_shape, etc.
969 it can be a sequence of string, map to the `keys`.
970 if None, will try to construct meta_keys by `key_{meta_key_postfix}`.
971 will extract the filename of input image to save classification results.
972 meta_key_postfix: `key_{postfix}` was used to store the metadata in `LoadImaged`.
973 so need the key to extract the metadata of input image, like filename, etc. default is `meta_dict`.
974 for example, for data with key `image`, the metadata by default is in `image_meta_dict`.
975 the metadata is a dictionary object which contains: filename, original_shape, etc.
976 this arg only works when `meta_keys=None`. if no corresponding metadata, set to `None`.
977 saver: the saver instance to save classification results, if None, create a CSVSaver internally.
978 the saver must provide `save(data, meta_data)` and `finalize()` APIs.
979 output_dir: if `saver=None`, specify the directory to save the CSV file.
980 filename: if `saver=None`, specify the name of the saved CSV file.
981 delimiter: the delimiter character in the saved file, default to "," as the default output type is `csv`.
982 to be consistent with: https://docs.python.org/3/library/csv.html#csv.Dialect.delimiter.
983 overwrite: if `saver=None`, indicate whether to overwriting existing CSV file content, if True,
984 will clear the file before saving. otherwise, will append new content to the CSV file.
985 flush: if `saver=None`, indicate whether to write the cache data to CSV file immediately
986 in this transform and clear the cache. default to True.
987 If False, may need user to call `saver.finalize()` manually or use `ClassificationSaver` handler.
988 allow_missing_keys: don't raise exception if key is missing.
989
990 """
991 super().__init__(keys, allow_missing_keys)
992 if len(self.keys) != 1:
993 raise ValueError("only 1 key is allowed when saving the classification result.")
994 self.saver = saver or CSVSaver(
995 output_dir=output_dir, filename=filename, overwrite=overwrite, flush=flush, delimiter=delimiter
996 )
997 self.flush = flush
998 self.meta_keys = ensure_tuple_rep(meta_keys, len(self.keys))
999 self.meta_key_postfix = ensure_tuple_rep(meta_key_postfix, len(self.keys))
1000
1001 def __call__(self, data):
1002 d = dict(data)

Callers

nothing calls this directly

Calls 3

CSVSaverClass · 0.90
ensure_tuple_repFunction · 0.90
__init__Method · 0.45

Tested by

no test coverage detected