elektronn2.data package¶
Submodules¶
elektronn2.data.cnndata module¶
-
class
elektronn2.data.cnndata.
AgentData
(input_node, side_target_node, path_prefix=None, raw_files=None, skel_files=None, vec_files=None, valid_skels=None, target_vec_ix=None, target_discrete_ix=None, abs_offset=None, aniso_factor=2)[source]¶ Bases:
elektronn2.data.cnndata.BatchCreatorImage
Load raw_cube, vec_prob_obj_cube and skelfiles + rel.offset
-
get_newslice
(position_l, direction_il, batch_size=1, source='train', aniso=True, z_shift=0, gamma=0, grey_augment_channels=[], r_max_scale=0.9, tracing_dir_prior_c=0.5, force_dense=False, flatfield_p=0.001, scale=1.0, last_ch_max_interp=False)[source]¶
-
getbatch
(batch_size=1, source='train', aniso=True, z_shift=0, gamma=0, grey_augment_channels=[], r_max_scale=0.9, tracing_dir_prior_c=0.5, force_dense=False, flatfield_p=0.001)[source]¶
-
getskel
(source)[source]¶ Draw an example skeleton according to sampling weight on training data, or randomly on valid data
-
load_data
()[source]¶ Parameters: - d_path/l_path (string) – Directories to load data from
- d_files/l_files (list) – List of data/target files in <path> directory (must be in the same order!). Each list element is a tuple in the form (<Name of h5-file>, <Key of h5-dataset>)
- cube_prios (list) – (not normalised) list of sampling weights to draw examples from the respective cubes. If None the cube sizes are taken as priorities.
- valid_cubes (list) – List of indices for cubes (from the file-lists) to use as validation data and exclude from training, may be empty list to skip performance estimation on validation data.
-
-
class
elektronn2.data.cnndata.
BatchCreatorImage
(input_node, target_node=None, d_path=None, l_path=None, d_files=None, l_files=None, cube_prios=None, valid_cubes=None, border_mode='crop', aniso_factor=2, target_vec_ix=None, target_discrete_ix=None, h5stream=False)[source]¶ Bases:
object
-
getbatch
(batch_size=1, source='train', grey_augment_channels=[], warp=False, warp_args=None, ignore_thresh=False, force_dense=False, affinities=False, nhood_targets=False, ret_ll_mask=False)[source]¶ Prepares a batch by randomly sampling, shifting and augmenting patches from the data
Parameters: - batch_size (int) – Number of examples in batch (for CNNs often just 1)
- source (string) – Data set to draw data from: ‘train’/’valid’
- flip (Bool) – If True examples are mirrored and rotated by 90 deg randomly
- grey_augment_channels (list) – List of channel indices to apply grey-value augmentation to
- ret_ll_mask (Bool) – If True additional information for reach batch example is returned. Currently implemented are two ll_mask arrays to indicate the targetling mode. The first dimension of those arrays is the batch_size!
- warp_on (Bool/Float(0,1)) – Whether warping/distortion augmentations are applied to examples (slow –> use multiprocessing). If this is a float number, warping is applied to this fraction of examples e.g. 0.5 –> every other example
- ignore_thresh (float) – If the fraction of negative targets in an example patch exceeds this threshold, this example is discarded (Negative targets are ignored for training [but could be used for unsupervised target propagation]).
- force_dense (Bool) – If True the targets are not sub-sampled according to the CNN output strides. Dense targets requires MFP in the CNN!
Returns: - data – [bs, ch, x, y] or [bs, ch, z, y, x] for 2d and 3d CNNS
- target – [bs, ch, x, y] or [bs, ch, z, y, x]
- ll_mask1 – (optional) [bs, n_target]
- ll_mask2 – (optional) [bs, n_target]
-
load_data
()[source]¶ Parameters: - d_path/l_path (string) – Directories to load data from
- d_files/l_files (list) – List of data/target files in <path> directory (must be in the same order!). Each list element is a tuple in the form (<Name of h5-file>, <Key of h5-dataset>)
- cube_prios (list) – (not normalised) list of sampling weights to draw examples from the respective cubes. If None the cube sizes are taken as priorities.
- valid_cubes (list) – List of indices for cubes (from the file-lists) to use as validation data and exclude from training, may be empty list to skip performance estimation on validation data.
-
read_files
()[source]¶ Image files on disk are expected to be in order (ch,x,y,z) or (x,y,z) But image stacks are returned as (z,ch,x,y) and target as (z,x,y,) irrespective of the order in the file. If the image files have no channel this dimension is extended to a singleton dimension.
-
warp_cut
(img, target, warp, warp_params)[source]¶ - sample_warp_params = dict(sample_aniso = True, lock_z = False,
- no_x_flip = False, warp_amount=1.0, perspective=True)
-
warp_stats
¶
-
elektronn2.data.image module¶
-
elektronn2.data.image.
make_affinities
(labels, nhood=None, size_thresh=1)[source]¶ Construct an affinity graph from a segmentation (IDs)
Segments with ID 0 are regarded as disconnected The spatial shape of the affinity graph is the same as of seg_gt. This means that some edges are are undefined and therefore treated as disconnected. If the offsets in nhood are positive, the edges with largest spatial index are undefined.
Connected components is run on the affgraph to relabel the IDs locally.
Parameters: - labels (4d np.ndarray, int (any precision)) – Volumes of segmentation IDs (bs, z, y, x)
- nhood (2d np.ndarray, int) – Neighbourhood pattern specifying the edges in the affinity graph Shape: (#edges, ndim) nhood[i] contains the displacement coordinates of edge i The number and order of edges is arbitrary
- size_thresh (int) – Size filters for connected components, smaller objects are mapped to BG
Returns: - aff (5d np.ndarray int16) – Affinity graph of shape (bs, #edges, x, y, z) 1: connected, 0: disconnected
- seg_gt – 4d np.ndarray int16 Affinity graph of shape (bs, x, y, z) Relabelling of components
-
elektronn2.data.image.
downsample_xy
(d, l, factor)[source]¶ Downsample by averaging :param d: data :param l: label :param factor: :return:
elektronn2.data.knossos_array module¶
-
class
elektronn2.data.knossos_array.
KnossosArray
(path, max_ram=1000, n_preload=2, fixed_mag=1)[source]¶ Bases:
object
Interfaces with knossos cubes, all axes are in zxy order!
-
n_f
¶
-
preload
(position, start_end=None, sync=False)[source]¶ preloads around position preload distance but at least to cover start-end
-
shape
¶
-
elektronn2.data.skeleton module¶
-
class
elektronn2.data.skeleton.
SkeletonMFK
(aniso_scale=2, name=None, skel_num=None)[source]¶ Bases:
object
Joints: all branches and end points / node terminatons (nodes not of deg 2) Branches: Joints of degree >= 3
-
get_loss_and_gradient
(new_position_s, cutoff_inner=0.3333333333333333, rise_factor=0.1)[source]¶ prediction_c (zxy) Zoned error surface: flat in inner hull (selected at cutoff_inner) constant gradient in “outer” hull towards nearest inner hull voxel gradient increasing with distance (scaled by rise_factor) for predictions outside hull
-
static
get_scale_factor
(radius, old_factor, scale_strenght)[source]¶ Parameters: - radius (predicted radius (not the true radius)) –
- old_factor (factor by which the radius prediction and the image was scaled) –
- scale_strenght (limits the maximal scale factor) –
Returns: Return type: new_factor
-
getbatch
(prediction, scale_strenght, **get_batch_kwargs)[source]¶ Parameters: - prediction ([[new_position_c, radius, ]]) –
- scale_strenght (limits the maximal scale factor for zoom) –
- get_batch_kwargs –
Returns: batch
Return type: img, target_img, target_grid, target_node
-
init_from_annotation
(skeleton_annotatation, min_radius=None, interpolation_resolution=0.5, interpolation_order=1)[source]¶
-
make_grid
= <elektronn2.utils.utils_basic.cache object>¶
-
map_hull
(hull_points)[source]¶ Distances take already into account the anisotropy in z (i.e. they are true distances) But all coordinates for hulls and vectors are still pixel coordinates
-
sample_local_direction_iso
(point, n_neighbors=6)[source]¶ For a point gives the local skeleton direction/orientation by fitting a line through the nearest neigbours, sign is randomly assigned
-
sample_tracing_direction_iso
(rng, local_direction_iso, c=0.5)[source]¶ Sample a direction close to the local direction there is a prior so that the normalised (0,1) angle of deviation a has this distribution: p(a) = 1/N * (1-c*a), where N= 1 - c/2, tmp is the inverse cdf of this shit
-
sample_tube_point
(rng, r_max_scale=0.9, joint_ratio=None)[source]¶ This is skeleton node based sampling: Go to a random node, sample a random orthogonal direction go a random distance into direction (uniform over the [0, r_max_scale * local maximal radius])
-
-
class
elektronn2.data.skeleton.
Trace
(linked_skel=None, aniso_scale=2, max_cutoff=200, uturn_detection_k=40, uturn_detection_thresh=0.45, uturn_detection_hold=10, feature_count=7)[source]¶ Bases:
object
Unless otherwise state all coordinates are in skeleton system (xyz) with z-axis anisotrope and all distances are in pixels (conversion to mu: 1/100)
-
avg_dist_self
¶
-
avg_dist_skel
¶
-
avg_seg_length
¶
-
max_dist_skel
¶
-
min_dist_self
¶
-
min_normed_dist_self
¶
-
runlength
¶
-
elektronn2.data.tracing_utils module¶
-
class
elektronn2.data.tracing_utils.
Tracer
(model, z_shift=0, data_source=None, bounding_box_zyx=None, trace_kwargs={'aniso_scale': 2}, modus='m', shotgun_registry=None, registry_interval=None, reference_radius=18.0)[source]¶ Bases:
object
-
trace
(position_l, direction_il, count, gamma=0, trace_xyz=None, linked_skel=None, check_for_lost_track=True, check_for_uturn=False, check_bb=True, profile=False, info_str=None, reject_obb_traces=False, initial_scale=None)[source]¶ Although psoition_l is in zyx order, the returned trace_obj is in xyz order
-
-
class
elektronn2.data.tracing_utils.
CubeShape
(shape, offset=None, center=None, input_excess=None, bbox_reduction=None)[source]¶ Bases:
object
-
class
elektronn2.data.tracing_utils.
ShotgunRegistry
(seeds_zyx, registry_extent, directions=None, debug=False, radius_discout=0.5, check_w=3, occupied_thresh=0.6, candidate_max_rel=0.75, candidate_max_min_margin=1.5)[source]¶ Bases:
object
-
check
(trace)[source]¶ Check if trace goes into masked volume. If so, find out to which trace tree this belongs and merge. Return False to stop tracing Mask seeds and volume mask by current trace’s log
W: window length to do check on
-
elektronn2.data.traindata module¶
Copyright (c) 2015 Marius Killinger, Sven Dorkenwald, Philipp Schubert All rights reserved
-
class
elektronn2.data.traindata.
Data
(n_lab=None)[source]¶ Bases:
object
Load and prepare data, Base-Obj
-
class
elektronn2.data.traindata.
MNISTData
(input_node, target_node, path=None, convert2image=True, warp_on=False, shift_augment=True, center=True)[source]¶
-
class
elektronn2.data.traindata.
PianoData
(input_node, target_node, path='/home/mkilling/devel/data/PianoRoll/Nottingham_enc.pkl', n_tap=20, n_lab=58)[source]¶
elektronn2.data.transformations module¶
-
elektronn2.data.transformations.
warp_slice
(img, ps, M, target=None, target_ps=None, target_vec_ix=None, target_discrete_ix=None, last_ch_max_interp=False, ksize=0.5)[source]¶ Parameters: - img – (f, z, x, y)
- ps – (spatial only) patch_size (z,x,y)
- M – forward tansform, must contain translations in source and target array!
- target – optional target array to be extracted in the same way
- target_ps –
- target_vec_ix – list of triples that denote vector value parts in the target array e.g. [(0,1,2),(4,5,6)] denotes two vectorfields separated by a scalar field in channel 3
Returns:
-
elektronn2.data.transformations.
get_tracing_slice
(img, ps, pos, z_shift=0, aniso_factor=2, sample_aniso=True, gamma=0, scale_factor=1.0, direction_iso=None, target=None, target_ps=None, target_vec_ix=None, target_discrete_ix=None, rng=None, last_ch_max_interp=False)[source]¶
-
exception
elektronn2.data.transformations.
WarpingOOBError
(*args, **kwargs)[source]¶ Bases:
exceptions.ValueError