Dataset information
MedDataset
def MedDataset(
dataframe:NoneType=None, image_col:str=None, mask_col:str='mask_path', path:NoneType=None,
img_list:NoneType=None, postfix:str='', apply_reorder:bool=True,
dtype:(<class 'fastMONAI.vision_core.MedImage'>, <class 'fastMONAI.vision_core.MedMask'>)=MedImage,
max_workers:int=1
):
A class to extract and present information about the dataset.
suggest_patch_size
def suggest_patch_size(
dataset:MedDataset, target_spacing:list=None, min_patch_size:list=None, max_patch_size:list=None, divisor:int=16
)->list:
Suggest optimal patch size based on dataset dimensions.
Uses median shape as the starting point but clamps to the minimum volume size per axis, ensuring the suggested patch fits ALL volumes without requiring padding during training.
Algorithm: 1. Use min(median, min_volume) per axis for safety 2. Round down to nearest multiple of divisor (16 for UNet compatibility) 3. Clamp to [min_patch_size, max_patch_size] bounds 4. Validate: error if min_patch_size exceeds smallest volume
Args: dataset: MedDataset instance with analyzed images. target_spacing: Target voxel spacing [x, y, z]. If None, uses dataset.get_suggestion()[‘target_spacing’]. min_patch_size: Minimum per dimension. Default [32, 32, 32]. max_patch_size: Maximum per dimension. Default [256, 256, 256]. divisor: Ensure divisibility (default 16 for UNet compatibility).
Returns: list: [patch_dim_0, patch_dim_1, patch_dim_2]
Example: >>> from fastMONAI.dataset_info import MedDataset >>> dataset = MedDataset(dataframe=df, mask_col=‘mask_path’, dtype=MedMask) >>> >>> # Use recommended spacing >>> patch_size = suggest_patch_size(dataset) >>> >>> # Use custom spacing >>> patch_size = suggest_patch_size(dataset, target_spacing=[1.0, 1.0, 2.0])
get_class_weights
def get_class_weights(
labels:(<built-in function array>, <class 'list'>), class_weight:str='balanced'
)->Tensor:
Calculates and returns the class weights.
Args: labels: An array or list of class labels for each instance in the dataset. class_weight: Defaults to ‘balanced’.
Returns: A tensor of class weights.