FastSurferCNN.utils.common¶
- class FastSurferCNN.utils.common.SubjectDirectory(subject_dir=None, **kwargs)[source]¶
Represent a subject directory.
Attributes
Try to return absolute path.
Try to return absolute path.
Try to return absolute path.
Get the id.
Try to return absolute path.
Try to return absolute path.
Try to return absolute path.
Gets the subject directory name.
Methods
can_resolve_attribute(attr_name)Check whether we can resolve the attribute.
can_resolve_filename(filename)Check whether we can resolve the file name.
fileexists_by_attribute(attr_name)Check if a file exists based on the provided attribute name.
fileexists_in_subject_folder(filepath)Check if file exists in the subject folder.
filename_by_attribute(attr_name)Retrieve a filename based on the provided attribute name.
filename_in_subject_folder(filepath)Construct a full absolute path from the subject directory and the passed filepath.
get_attribute(attr_name)Give the requested attribute.
has_attribute(attr_name)Check if the attribute is set.
- fileexists_by_attribute(attr_name)[source]¶
Check if a file exists based on the provided attribute name.
- filename_in_subject_folder(filepath)[source]¶
Construct a full absolute path from the subject directory and the passed filepath.
- get_attribute(attr_name)[source]¶
Give the requested attribute.
- Parameters:
- attr_name
str Name of the attribute to return.
- attr_name
- Returns:
- Raises:
AttributeErrorIf the subject has no attribute with the given name.
- property asegdkt_segfile¶
Try to return absolute path.
If the asegdkt_segfile is a relative path, it will be interpreted as relative to folder.
- Returns:
PathPath to segmentation file.
- property conf_name¶
Try to return absolute path.
If the conformed_t1_file is a relative path, it will be interpreted as relative to folder.
- Returns:
PathThe path to the conformed image file.
- property copy_orig_name¶
Try to return absolute path.
If the copy_orig_t1_file is a relative path, it will be interpreted as relative to folder.
- Returns:
PathThe copy of orig name.
- property main_segfile¶
Try to return absolute path.
If the main_segfile is a relative path, it will be interpreted as relative to folder.
- Returns:
PathPath to the main segfile.
- property orig_name¶
Try to return absolute path.
If the native_t1_file is a relative path, it will be interpreted as relative to folder.
- Returns:
strThe orig name.
- class FastSurferCNN.utils.common.SubjectList(args, flags=None, **assign)[source]¶
Represent a list of subjects.
Attributes
Give the flags.
Methods
Check if all entries in subjects are actually files.
Find common suffix, if all entries in the subject list share a common suffix.
Try to create the subject directory.
- are_all_subject_files()[source]¶
Check if all entries in subjects are actually files.
This is performed asynchronously internally.
- FastSurferCNN.utils.common.assert_no_root()[source]¶
Check whether the user is the root user and raises an error message is so.
- Returns:
boolWhether the user is root or not.
- FastSurferCNN.utils.common.find_device(device='auto', flag_name='device', min_memory=0, default_cuda_device='cuda')[source]¶
Create a device object from the device string passed.
Includes detection of devices if device is not defined or “auto”.
- Parameters:
- device
torch.device,str, default=”auto” The device to search for and test following pytorch device naming conventions, e.g. ‘cuda:0’, ‘cpu’, etc.
- flag_name
str Name of the corresponding flag for error messages (default: ‘device’).
- min_memory
int The minimum memory in bytes required for cuda-devices to be valid (default: 0, works always).
- default_cuda_device
str,torch.device, default=”cuda” Default cuda device to use, if cuda is available and device is “auto”.
- device
- Returns:
- device:
torch.device The torch.device object.
- device:
- FastSurferCNN.utils.common.handle_cuda_memory_exception(exception)[source]¶
Handle CUDA out of memory exception and print a help text.
- Parameters:
- exception
builtins.BaseException Received exception.
- exception
- Returns:
boolWhether the exception was a RuntimeError caused by Cuda out memory.
- FastSurferCNN.utils.common.suppress_stderr()[source]¶
Contextmanager that suppresses all output on stderr.
Notes
This Context Manager does not work with multiple threads, as
sys.stderris shared between threads.
- FastSurferCNN.utils.common.suppress_stdout()[source]¶
Contextmanager that suppresses all output on stdout.
Notes
This Context Manager does not work with multiple threads, as
sys.stdoutis shared between threads.