def __init__(self, name, volume_config, slicing_config, transform_config=None): assert isinstance(volume_config, dict) assert isinstance(slicing_config, dict) assert 'raw' in volume_config assert 'ground_truth' in volume_config volume_config = deepcopy(volume_config) # Get kwargs for raw volume raw_volume_kwargs = dict(volume_config.get('raw')) raw_volume_kwargs.update(slicing_config) # Build raw volume self.raw_volume = RawVolume(name=name, **raw_volume_kwargs) # Get kwargs for segmentation volume segmentation_volume_kwargs = dict(volume_config.get('ground_truth')) segmentation_volume_kwargs.update(slicing_config) self.affinity_config = segmentation_volume_kwargs.pop('affinity_config', None) # Build segmentation volume self.segmentation_volume = SegmentationVolume(name=name, **segmentation_volume_kwargs) volumes_to_load = [self.raw_volume, self.segmentation_volume] super().__init__(*volumes_to_load, sync=True) # Set master config (for transforms) self.transform_config = {} if transform_config is None else deepcopy(transform_config) # Get transforms self.transforms = self.get_transforms()
def __init__(self, name, volume_config, slicing_config, defect_augmentation_config, master_config=None): assert isinstance(volume_config, dict) assert isinstance(slicing_config, dict) assert isinstance(defect_augmentation_config, dict) assert 'raw' in volume_config assert 'segmentation' in volume_config volume_config = deepcopy(volume_config) self.scaling_factors = volume_config.pop("scaling_factors") # Get kwargs for raw volume raw_volume_kwargs = dict(volume_config.get('raw')) # check if we have special dict entries for names in the defect augmentation # slicing config augmentation_config = deepcopy(defect_augmentation_config) for slicing_key, slicing_item in augmentation_config[ 'artifact_source']['slicing_config'].items(): if isinstance(slicing_item, dict): new_item = augmentation_config['artifact_source'][ 'slicing_config'][slicing_key][name] augmentation_config['artifact_source']['slicing_config'][ slicing_key] = new_item raw_volume_kwargs.update( {'defect_augmentation_config': augmentation_config}) raw_volume_kwargs.update(slicing_config) # Build raw volume self.raw_volume = RawVolumeWithDefectAugmentation(name=name, **raw_volume_kwargs) # Get kwargs for segmentation volume segmentation_volume_kwargs = dict(volume_config.get('segmentation')) segmentation_volume_kwargs.update(slicing_config) self.affinity_config = segmentation_volume_kwargs.pop( 'affinity_config', None) # Build segmentation volume self.segmentation_volume = SegmentationVolume( name=name, **segmentation_volume_kwargs) rejection_threshold = volume_config.get('rejection_threshold', 0.92) super().__init__(self.raw_volume, self.segmentation_volume, sync=True, rejection_dataset_indices=1, rejection_criterion=RejectSingleLabelVolumes( 1.0, 0.95)) # Set master config (for transforms) self.master_config = {} if master_config is None else master_config # Get transforms self.transforms = self.get_transforms()
def __init__(self, name, volume_config, slicing_config, transform_config=None, inference_mode=False): assert isinstance(volume_config, dict) assert isinstance(slicing_config, dict) assert 'volume_keys_to_load' in volume_config volume_config = deepcopy(volume_config) volumes_to_load = [] volume_keys_to_load = volume_config.pop("volume_keys_to_load") for volume_key in volume_keys_to_load: if volume_key not in volume_config: print("Warning: no kwargs passed for volume {}".format( volume_key)) # Get default slicing configs: current_volume_kwargs = deepcopy(slicing_config) current_volume_kwargs.update(volume_config.get(volume_key, {})) dtype = current_volume_kwargs.get("dtype") dtype = dtype[name] if isinstance(dtype, dict) else dtype if inference_mode: current_volume_kwargs["return_index_spec"] = True if dtype == "float32": volumes_to_load.append( RawVolume(name=name, **current_volume_kwargs)) elif dtype == "int32" or dtype == "int64": volumes_to_load.append( SegmentationVolume(name=name, **current_volume_kwargs)) else: raise ValueError( "Atm only float32 and int32 datasets are supported. {} was given" .format(dtype)) super().__init__(*volumes_to_load, return_index_spec=inference_mode, sync=True) # Set master config (for transforms) self.transform_config = {} if transform_config is None else deepcopy( transform_config) # Get transforms self.transforms = self.get_transforms()
def __init__(self, name, volume_config, slicing_config, master_config=None): assert isinstance(volume_config, dict) assert isinstance(slicing_config, dict) assert 'raw' in volume_config assert 'segmentation' in volume_config # Get kwargs for raw volume raw_volume_kwargs = dict(volume_config.get('raw')) raw_volume_kwargs.update(slicing_config) # Build raw volume self.raw_volume = RawVolume(name=name, **raw_volume_kwargs) # Get kwargs for segmentation volume segmentation_volume_kwargs = dict(volume_config.get('segmentation')) segmentation_volume_kwargs.update(slicing_config) self.affinity_config = segmentation_volume_kwargs.pop( 'affinity_config', None) # Build segmentation volume self.segmentation_volume = SegmentationVolume( name=name, **segmentation_volume_kwargs) rejection_threshold = volume_config.get('rejection_threshold', 0.1) # print("reject at", rejection_threshold) # Initialize zipreject rejecter = RejectNonZeroThreshold(rejection_threshold) super(PlatynerisDataset, self).__init__(self.raw_volume, self.segmentation_volume, sync=True, rejection_dataset_indices=1, rejection_criterion=rejecter) # Set master config (for transforms) self.master_config = {} if master_config is None else master_config # Get transforms self.transforms = self.get_transforms()
'C': 'raw' }, 'data_slice': { 'A': ':, :, :', 'B': '20:32, 300:948, 300:948', 'C': ':75, :, :' }, 'stride': { 'A': [4, 128, 128], 'B': [4, 128, 128], 'C': [4, 128, 128] }, 'window_size': { 'A': [12, 648, 648], 'B': [12, 648, 648], 'C': [12, 648, 648] } } segmentation = SegmentationVolume(name='B', **segmentation_volume_kwargs)[0] raw = RawVolume(name='B', **raw_volume_kwargs)[0] f = h5py.File('groundtruth.hdf5', 'a') for key in f.keys(): del f[key] f.create_dataset('raw', data=raw) f.create_dataset('segmentation', data=segmentation) f.close()
def __init__(self, name, volume_config, slicing_config, defect_augmentation_config, master_config=None): assert isinstance(volume_config, dict) assert isinstance(slicing_config, dict) assert isinstance(defect_augmentation_config, dict) assert 'raw' in volume_config assert 'segmentation' in volume_config volume_config = deepcopy(volume_config) # Get kwargs for raw volume raw_volume_kwargs = dict(volume_config.get('raw')) # check if we have special dict entries for names in the defect augmentation # slicing config augmentation_config = deepcopy(defect_augmentation_config) for slicing_key, slicing_item in augmentation_config[ 'artifact_source']['slicing_config'].items(): if isinstance(slicing_item, dict): new_item = augmentation_config['artifact_source'][ 'slicing_config'][slicing_key][name] augmentation_config['artifact_source']['slicing_config'][ slicing_key] = new_item raw_volume_kwargs.update( {'defect_augmentation_config': augmentation_config}) raw_volume_kwargs.update(slicing_config) # Build raw volume ignore_slice_list = deepcopy( augmentation_config.get("ignore_slice_list", None)) if isinstance(ignore_slice_list, dict): ignore_slice_list = ignore_slice_list.get(name, []) self.raw_volume = RawVolumeWithDefectAugmentation( name=name, ignore_slice_list=ignore_slice_list, **raw_volume_kwargs) # Get kwargs for segmentation volume segmentation_volume_kwargs = dict(volume_config.get('segmentation')) segmentation_volume_kwargs.update(slicing_config) self.affinity_config = segmentation_volume_kwargs.pop( 'affinity_config', None) # Build segmentation volume self.segmentation_volume = SegmentationVolume( name=name, **segmentation_volume_kwargs) volumes_to_load = [self.raw_volume, self.segmentation_volume] # Load additional masks: self.extra_masks_volume = None if volume_config.get('extra_masks', False): extra_masks_kwargs = dict(volume_config.get('extra_masks')) extra_masks_kwargs.update(slicing_config) self.extra_masks_volume = SegmentationVolume(name=name, **extra_masks_kwargs) volumes_to_load.append(self.extra_masks_volume) rejection_threshold = volume_config.get('rejection_threshold', 0.5) super().__init__(*volumes_to_load, sync=True, rejection_dataset_indices=1, rejection_criterion=RejectSingleLabelVolumes( 1.0, rejection_threshold, defected_label=master_config.get( 'duplicate_GT_defected_slices', {}).get('defect_label', -1))) # Set master config (for transforms) self.master_config = {} if master_config is None else deepcopy( master_config) # Get transforms self.transforms = self.get_transforms()
def __init__(self, name, volume_config, slicing_config, defect_augmentation_config, master_config=None): raise DeprecationWarning("Use newer version in segmfriends") assert isinstance(volume_config, dict) assert isinstance(slicing_config, dict) assert isinstance(defect_augmentation_config, dict) assert 'raw' in volume_config assert 'segmentation' in volume_config assert 'various_masks' in volume_config volume_config = deepcopy(volume_config) # Get kwargs for raw volume raw_volume_kwargs = dict(volume_config.get('raw')) # check if we have special dict entries for names in the defect augmentation # slicing config augmentation_config = deepcopy(defect_augmentation_config) for slicing_key, slicing_item in augmentation_config[ 'artifact_source']['slicing_config'].items(): if isinstance(slicing_item, dict): new_item = augmentation_config['artifact_source'][ 'slicing_config'][slicing_key][name] augmentation_config['artifact_source']['slicing_config'][ slicing_key] = new_item raw_volume_kwargs.update( {'defect_augmentation_config': augmentation_config}) raw_volume_kwargs.update(slicing_config) # Build raw volume self.raw_volume = RawVolumeWithDefectAugmentation(name=name, **raw_volume_kwargs) # Get kwargs for segmentation volume segmentation_volume_kwargs = dict(volume_config.get('segmentation')) segmentation_volume_kwargs.update(slicing_config) self.affinity_config = segmentation_volume_kwargs.pop( 'affinity_config', None) # Build segmentation volume self.segmentation_volume = SegmentationVolume( name=name, **segmentation_volume_kwargs) # Load additional masks: various_masks_kwargs = dict(volume_config.get('various_masks')) various_masks_kwargs.update(slicing_config) self.mask_volume = SegmentationVolume(name=name, **various_masks_kwargs) rejection_threshold = volume_config.get('rejection_threshold', 0.5) super().__init__(self.raw_volume, self.segmentation_volume, self.mask_volume, sync=True, rejection_dataset_indices=1, rejection_criterion=RejectSingleLabelVolumes( 1.0, rejection_threshold, defected_label=master_config.get( 'duplicate_GT_defected_slices', {}).get('defect_label', -1))) # Set master config (for transforms) self.master_config = {} if master_config is None else deepcopy( master_config) # Get transforms self.transforms = self.get_transforms()