U Ph@sddlmZddlmZddlmZddlmZddlm Z m Z m Z m Z m Z mZdddgZGd ddeZGd ddeZGd ddeZd S) ) annotations)UserDict)partial)Any)maxmeanmedianmin percentilestd OperationsSampleOperationsSummaryOperationsc@s"eZdZdZddddddZdS)r z+ Base class of operation interface rdictdatakwargsreturnc sfdd|jDS)a For key-value pairs in the self.data, if the value is a callable, then this function will apply the callable to the input data. The result will be written under the same key under the output dict. Args: data: input data. Returns: a dictionary which has same keys as the self.data if the value is callable. cs&i|]\}}t|r||fqS)callable.0kvrrrO/home/dell461/cl/sdc2/HISourceFinder-master-l/src/monai/auto3dseg/operations.py )sz'Operations.evaluate..ritemsselfrrrrrevaluates zOperations.evaluateN)__name__ __module__ __qualname____doc__r!rrrrr scs8eZdZdZddddZddddfd d ZZS) r aY Apply statistical operation to a sample (image/ndarray/tensor). Notes: Percentile operation uses a partial function that embeds different kwargs (q). In order to print the result nicely, data_addon is added to map the numbers generated by percentile to different keys ("percentile_00_5" for example). Annotation of the postfix means the percentage for percentile computation. For example, _00_5 means 0.5% and _99_5 means 99.5%. Example: .. code-block:: python # use the existing operations import numpy as np op = SampleOperations() data_np = np.random.rand(10, 10).astype(np.float64) print(op.evaluate(data_np)) # add a new operation op.update({"sum": np.sum}) print(op.evaluate(data_np)) Nonerc Cs8tttttttddddgdd|_ddd d d |_dS) Ng? ZgX@)q)rrrr stdevr )r r)r )r )r )percentile_00_5percentile_10_0percentile_90_0percentile_99_5) rrrr r rr r data_addonr rrr__init__Fs zSampleOperations.__init__rrrc s~tj|f|}|jD]@\}}|d}|d}t|tr||kr|||||iq|D]\}}|||<qd|S)z Applies the callables to the data, and convert the numerics to list or Python numeric types (int/float). Args: data: input data rr,)superr!r3r isinstancetupleupdatetolist)r rrretrrcacheidx __class__rrr!VszSampleOperations.evaluate)r"r#r$r%r5r! __classcell__rrr>rr ,sc@s0eZdZdZddddZddddd d Zd S) raW Apply statistical operation to summarize a dict. The key-value looks like: {"max", "min" ,"mean", ....}. The value may contain multiple values in a list format. Then this operation will apply the operation to the list. Typically, the dict is generated by multiple `SampleOperation` and `concat_multikeys_to_dict` functions. Examples: .. code-block:: python import numpy as np data = { "min": np.random.rand(4), "max": np.random.rand(4), "mean": np.random.rand(4), "sum": np.random.rand(4), } op = SummaryOperations() print(op.evaluate(data)) # "sum" is not registered yet, so it won't contain "sum" op.update({"sum", np.sum}) print(op.evaluate(data)) # output has "sum" r&r'c Cstttttttttd |_dS)N) rrrr r+r/r0r1r2)rrr rr4rrrr5szSummaryOperations.__init__rrrc sfdd|jDS)z Applies the callables to the data, and convert the numerics to list or Python numeric types (int/float). Args: data: input data cs6i|].\}}t|r|kr|||fqSr)rr:rrrrrs z.SummaryOperations.evaluate..rrrrrr!szSummaryOperations.evaluateN)r"r#r$r%r5r!rrrrrjs N) __future__r collectionsr functoolsrtypingr0monai.transforms.utils_pytorch_numpy_unificationrrrr r r __all__r r rrrrr s      >