tf_unet Package¶
unet Module¶
Created on Jul 28, 2016
author: jakeret
-
class
tf_unet.unet.Trainer(net, batch_size=1, optimizer=u'momentum', opt_kwargs={})[source]¶ Bases:
objectTrains a unet instance
Parameters: - net – the unet instance to train
- batch_size – size of training batch
- optimizer – (optional) name of the optimizer to use (momentum or adam)
- opt_kwargs – (optional) kwargs passed to the learning rate (momentum opt) and to the optimizer
-
prediction_path= u'prediction'¶
-
train(data_provider, output_path, training_iters=10, epochs=100, dropout=0.75, display_step=1, restore=False)[source]¶ Lauches the training process
Parameters: - data_provider – callable returning training and verification data
- output_path – path where to store checkpoints
- training_iters – number of training mini batch iteration
- epochs – number of epochs
- dropout – dropout probability
- display_step – number of steps till outputting stats
- restore – Flag if previous model should be restored
-
verification_batch_size= 4¶
-
class
tf_unet.unet.Unet(channels=3, n_class=2, cost=u'cross_entropy', cost_kwargs={}, **kwargs)[source]¶ Bases:
objectA unet implementation
Parameters: - channels – (optional) number of channels in the input image
- n_class – (optional) number of output labels
- cost – (optional) name of the cost function. Default is ‘cross_entropy’
- cost_kwargs – (optional) kwargs passed to the cost function. See Unet._get_cost for more options
-
predict(model_path, x_test)[source]¶ Uses the model to create a prediction for the given data
Parameters: - model_path – path to the model checkpoint to restore
- x_test – Data to predict on. Shape [n, nx, ny, channels]
Returns prediction: The unet prediction Shape [n, px, py, labels] (px=nx-self.offset/2)
-
tf_unet.unet.create_conv_net(x, keep_prob, channels, n_class, layers=3, features_root=16, filter_size=3, pool_size=2, summaries=True)[source]¶ Creates a new convolutional unet for the given parametrization.
Parameters: - x – input tensor, shape [?,nx,ny,channels]
- keep_prob – dropout probability tensor
- channels – number of channels in the input image
- n_class – number of output labels
- layers – number of layers in the net
- features_root – number of features in the first layer
- filter_size – size of the convolution filter
- pool_size – size of the max pooling operation
- summaries – Flag if summaries should be created
image_util Module¶
author: jakeret
-
class
tf_unet.image_util.BaseDataProvider(a_min=None, a_max=None)[source]¶ Bases:
objectAbstract base class for DataProvider implementation. Subclasses have to overwrite the _next_data method that load the next data and label array. This implementation automatically clips the data with the given min/max and normalizes the values to (0,1]. To change this behavoir the _process_data method can be overwritten. To enable some post processing such as data augmentation the _post_process method can be overwritten.
Parameters: - a_min – (optional) min value used for clipping
- a_max – (optional) max value used for clipping
-
channels= 1¶
-
n_class= 2¶
-
class
tf_unet.image_util.ImageDataProvider(search_path, a_min=None, a_max=None, data_suffix=u'.tif', mask_suffix=u'_mask.tif')[source]¶ Bases:
tf_unet.image_util.BaseDataProviderGeneric data provider for images, supports gray scale and colored images. Assumes that the data images and label images are stored in the same folder and that the labels have a different file suffix e.g. ‘train/fish_1.tif’ and ‘train/fish_1_mask.tif’
Usage: data_provider = ImageDataProvider(”..fishes/train/*.tif”)
Parameters: - search_path – a glob search pattern to find all data and label images
- a_min – (optional) min value used for clipping
- a_max – (optional) max value used for clipping
- data_suffix – suffix pattern for the data images. Default ‘.tif’
- mask_suffix – suffix pattern for the label images. Default ‘_mask.tif’
-
n_class= 2¶
util Module¶
Created on Aug 10, 2016
author: jakeret
-
tf_unet.util.combine_img_prediction(data, gt, pred)[source]¶ Combines the data, grouth thruth and the prediction into one rgb image
Parameters: - data – the data tensor
- gt – the ground thruth tensor
- pred – the prediction tensor
Returns img: the concatenated rgb image
-
tf_unet.util.crop_to_shape(data, shape)[source]¶ Crops the array to the given image shape by removing the border (expects a tensor of shape [batches, nx, ny, channels].
Parameters: - data – the array to crop
- shape – the target shape