FastSurferCNN.utils.common¶
- class FastSurferCNN.utils.common.SerialExecutor[source]¶
Represent a serial executor.
Methods
map
(fn, *iterables[, timeout, chunksize])The map function.
shutdown
([wait, cancel_futures])Clean-up the resources associated with the Executor.
submit
(_SerialExecutor__fn, *args, **kwargs)A callable function that returns a Future representing the result.
- map(fn, *iterables, timeout=None, chunksize=-1)[source]¶
The map function.
- Parameters:
- Returns:
Iterator
[_T
]An iterator that yields the results of applying ‘fn’ to the items of ‘iterables’.
- submit(_SerialExecutor__fn, *args, **kwargs)[source]¶
A callable function that returns a Future representing the result.
- Parameters:
- __fn
Callable
[…,_T
] A callable function to be executed.
- *args
Potential arguments to be passed to the callable function.
- **kwargs
Keyword arguments to be passed to the callable function.
- __fn
- Returns:
- “Future[
_T
]” A Future object representing the execution result of the callable function.
- “Future[
- class FastSurferCNN.utils.common.SubjectDirectory(**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)Return the full path to the file.
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.
- get_attribute(attr_name)[source]¶
Give the requested attribute.
- Parameters:
- attr_name
str
Name of the attribute to return.
- attr_name
- Returns:
- Raises:
AttributeError
If 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:
Path
Path 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:
Path
The 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:
Path
The 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:
Path
Path 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:
str
The 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:
bool
Whether the user is root or not.
- FastSurferCNN.utils.common.find_device(device='auto', flag_name='device', min_memory=0)[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
The device to search for and test following pytorch device naming conventions, e.g. ‘cuda:0’, ‘cpu’, etc. (default: ‘auto’).
- 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).
- 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:
bool
Whether the exception was a RuntimeError caused by Cuda out memory.
- FastSurferCNN.utils.common.iterate(pool, func, iterable)[source]¶
Iterate over iterable, yield pairs of elements and func(element).
- Parameters:
- pool
Executor
The Executor object (dummy object to have a common API with pipeline).
- func
callable()
Function to use.
- iterable
Iterable
Iterable to draw objects to process with func from.
- pool
- Yields:
- element
_Ti
Elements
_T
Results of func corresponding to element: func(element).
- element
- FastSurferCNN.utils.common.pipeline(pool, func, iterable, *, pipeline_size=1)[source]¶
Pipeline a function to be executed in the pool.
Analogous to iterate, but run func in a different thread for the next element while the current element is returned.
- Parameters:
- pool
Executor
Thread pool executor for parallel execution.
- func
callable()
Function to use.
- iterable
Iterable
Iterable containing input elements.
- pipeline_size
int
, default=1 Size of the processing pipeline.
- pool
- Yields:
- element
_Ti
Elements
_T
Results of func corresponding to element: func(element).
- element