NVIDIA Clara Train 3.1
3.1

ai4med.components.eval_writers package

class EvalWriter(field: str)

Bases: abc.ABC

EvalWriters are used by the Evaluation Workflow to manage evaluation results, which are stored in a data dict during the evaluation workflow. Each item in the dict is called a field.

This class defines the methods that an eval writer must implement.

Parameters

field (str) – name of the field that this writer manages.

abstract check_results_exist(input_file_name: str)

Checks whether the evaluation results of the specified input file exists.

Each eval writer manages some evaluation results of the input data. The eval writer must be able to tell whether the results it manages exists on disk.

Parameters

input_file_name (str) – name of the input

Returns: bool, whether the results exist

finalize()

Optional method to finalize any writing for eval_writers, e.g., ai4med.components.eval_writers.write_classification_result.WriteClassificationResult, that only writes one summary file.

abstract load_results(input_file_name: str, transform_ctx: ai4med.common.transform_ctx.TransformContext)

Loads evaluation results managed by this writer from disk into a Transform Context.

Parameters
  • input_file_name (str) – name of the input

  • transform_ctx (TransformContext) – the transform context to store the loaded data.

abstract write(input_file_name: str, data_dict: dict)

Writes evaluation result stored in the data_dict to disk.

Parameters
  • input_file_name (str) – name of the input

  • data_dict (dict) – the data dict that stores the evaluation results

class WriteClassificationResult(field, write_path, overwrite=True, ordered=True)

Bases: ai4med.components.eval_writers.eval_writer.EvalWriter

Writes array of prediction results to a csv

check_results_exist(input_file_name)

Checks if the class’ dict has the given filename key

finalize()

Writes the prediction dict to a csv

load_results(input_file_name, transform_ctx: ai4med.common.transform_ctx.TransformContext)

Returns the corresponding value for the file_name key

write(input_file_name, data_dict)

Write row to csv. First column with be filename, following columns will be prediction results

class WriteNifti(field: str, write_path: str, compressed=True, dtype='float32', use_identity=False, data_root_dir='', revert_canonical=False)

Bases: ai4med.components.eval_writers.eval_writer.EvalWriter

Writes field’s data as a nifti image. The absolute path to the output file is derived from the input file name, as follows:

<write_path>/[input_file_rel_path]/<input_file_basename>/<input_file_basename>_<field>.nii

The input_file_rel_path is computed only when data_root_dir is non-empty: it is the input file’s relative path to the specified data_root_dir. This input_file_rel_path is necessary to differentiate file names when input files in different sub-folders happen to have the same base names. If you don’t have cases like this, data_root_dir can be left empty.

Parameters
  • field (str) – name of the field to manage

  • write_path (str) – path for the output file

  • compressed (bool) – whether the file should be compressed (Default: True)

  • dtype (str) – image data type. Must be an acceptable NumPy data type (Default: float32)

  • use_identity (bool) – whether to use identify for affine matrix (Default: False)

  • data_root_dir (str) – if not empty, it specifies the beginning parts of the input file’s absolute path. This is used to compute input_file_rel_path, the relative path to the file from data_root_dir to preserve folder structure when saving in case there are files in different folders with the same filenames.

  • revert_canonical (bool) – Revert the as close canonical operation in LoadNifti (Default: False)

check_results_exist(input_file_name: str)

Checks whether the nifti file exists.

Note

The file to check is derived from the input_file_name as described above with input_file_basename being input_file_name without extensions.

Parameters

input_file_name (str) – name of the input file

load_results(input_file_name: str, transform_ctx: ai4med.common.transform_ctx.TransformContext)

Loads the result nifti image (that was created previously).

Note

The nifti image file name is derived from the input_file_name as described above with input_file_basename being input_file_name without extensions.

Parameters
  • input_file_name (str) – name of input file

  • transform_ctx (TransformContext) – the transform context to load image into

write(input_file_name: str, data_dict)

Writes the data of the ‘field’ in the data_dict to file as a nifti image

Parameters
  • input_file_name (str) – name of the input

  • data_dict (dict) – data dict

© Copyright 2020, NVIDIA. Last updated on Feb 2, 2023.