API documentation

barrista.config module

The configuration module for barrista.

It is possible to programmatically change the configuration. For this, import barrista.config and edit the values as required before importing any other of the submodules. The configuration change is then taken into account.

barrista.config.LAYER_TYPES = {'Log': ['LogParameter'], 'SoftmaxWithLoss': ['SoftmaxParameter', 'LossParameter'], 'HingeLoss': ['HingeLossParameter'], 'ReLU': ['ReLUParameter'], 'Reduction': ['ReductionParameter'], 'Slice': ['SliceParameter'], 'InnerProduct': ['InnerProductParameter'], 'Accuracy': ['AccuracyParameter'], 'SPP': ['SPPParameter'], 'Dropout': ['DropoutParameter'], 'InfogainLoss': ['InfogainLossParameter'], 'DummyData': ['DummyDataParameter'], 'WindowData': ['WindowDataParameter'], 'BatchNorm': ['BatchNormParameter'], 'Data': ['DataParameter'], 'Concat': ['ConcatParameter'], 'MultinomialLogisticLoss': ['LossParameter'], 'VariableHingeLoss': ['LossParameter'], 'ContrastiveLoss': ['ContrastiveLossParameter'], 'Filter': [], 'Softmax': ['SoftmaxParameter'], 'Embed': ['EmbedParameter'], 'MVN': ['MVNParameter'], 'TanH': ['TanHParameter'], 'EuclideanLoss': ['LossParameter'], 'SigmoidCrossEntropyLoss': ['LossParameter'], 'HDF5Output': ['HDF5OutputParameter'], 'Scale': ['ScaleParameter'], 'Reshape': ['ReshapeParameter'], 'Split': [], 'PReLU': ['PReLUParameter'], 'Power': ['PowerParameter'], 'Python': ['PythonParameter'], 'Resample': [], 'Flatten': ['FlattenParameter'], 'ImageData': ['ImageDataParameter'], 'ArgMax': ['ArgMaxParameter'], 'Pooling': ['PoolingParameter'], 'AbsVal': [], 'Exp': ['ExpParameter'], 'Eltwise': ['EltwiseParameter'], 'HDF5Data': ['HDF5DataParameter'], 'Silence': [], 'Convolution': ['ConvolutionParameter'], 'Sigmoid': ['SigmoidParameter'], 'LRN': ['LRNParameter'], 'Threshold': ['ThresholdParameter']}

This dictionary specifies the layer types and their configuration parameters. The keys are the layer keys, and the values a list of strings, where each string is the name of a parameter prefixed with _caffe_pb2. .

barrista.design module

This module contains classes and functions to design networks with caffe.

For the layer constructing functions, None is used to mark a parameter as unset (this is important in protobuf)!

barrista.design.AbsValLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None)
barrista.design.AccuracyLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Accuracy_axis=None, Accuracy_top_k=None, Accuracy_ignore_label=None)
barrista.design.ArgMaxLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, ArgMax_axis=None, ArgMax_top_k=None, ArgMax_out_max_val=None)
barrista.design.BatchNormLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, BatchNorm_use_global_stats=None, BatchNorm_eps=None, BatchNorm_moving_average_fraction=None)
barrista.design.ConcatLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Concat_axis=None, Concat_concat_dim=None)
barrista.design.ContrastiveLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, ContrastiveLoss_legacy_version=None, ContrastiveLoss_margin=None)
barrista.design.ConvolutionLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Convolution_stride_h=None, Convolution_stride_w=None, Convolution_stride=None, Convolution_bias_term=None, Convolution_axis=None, Convolution_bias_filler=None, Convolution_group=None, Convolution_pad=None, Convolution_dilation=None, Convolution_weight_filler=None, Convolution_engine=None, Convolution_pad_h=None, Convolution_force_nd_im2col=None, Convolution_pad_w=None, Convolution_kernel_w=None, Convolution_num_output=None, Convolution_kernel_h=None, Convolution_kernel_size=None)
barrista.design.DataLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Data_mirror=None, Data_backend=None, Data_scale=None, Data_force_encoded_color=None, Data_source=None, Data_crop_size=None, Data_batch_size=None, Data_rand_skip=None, Data_mean_file=None, Data_prefetch=None)
barrista.design.DropoutLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Dropout_dropout_ratio=None)
barrista.design.DummyDataLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, DummyData_height=None, DummyData_num=None, DummyData_data_filler=None, DummyData_width=None, DummyData_channels=None, DummyData_shape=None)
barrista.design.EltwiseLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Eltwise_operation=None, Eltwise_stable_prod_grad=None, Eltwise_coeff=None)
barrista.design.EmbedLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Embed_bias_term=None, Embed_bias_filler=None, Embed_weight_filler=None, Embed_num_output=None, Embed_input_dim=None)
barrista.design.EuclideanLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Loss_normalize=None, Loss_ignore_label=None, Loss_normalization=None)
barrista.design.ExpLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Exp_scale=None, Exp_base=None, Exp_shift=None)
barrista.design.FilterLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None)
barrista.design.FlattenLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Flatten_axis=None, Flatten_end_axis=None)
barrista.design.HDF5DataLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, HDF5Data_shuffle=None, HDF5Data_source=None, HDF5Data_batch_size=None)
barrista.design.HDF5OutputLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, HDF5Output_file_name=None)
barrista.design.HingeLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, HingeLoss_norm=None)
barrista.design.ImageDataLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, ImageData_mirror=None, ImageData_shuffle=None, ImageData_crop_size=None, ImageData_scale=None, ImageData_root_folder=None, ImageData_source=None, ImageData_new_height=None, ImageData_batch_size=None, ImageData_is_color=None, ImageData_rand_skip=None, ImageData_mean_file=None, ImageData_new_width=None)
barrista.design.InfogainLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, InfogainLoss_source=None)
barrista.design.InnerProductLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, InnerProduct_bias_term=None, InnerProduct_axis=None, InnerProduct_bias_filler=None, InnerProduct_transpose=None, InnerProduct_weight_filler=None, InnerProduct_num_output=None)
barrista.design.LRNLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, LRN_norm_region=None, LRN_engine=None, LRN_beta=None, LRN_alpha=None, LRN_k=None, LRN_local_size=None)
class barrista.design.LayerSpecification(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None)[source]

Bases: object

Describes one caffe layer.

Parameters:
  • bottoms – list(string) or None. If set, specifies the inputs. If unset, will be automatically wired to the preceeding layer top[0].
  • tops – list(string) or None. If set, specifies the top names of this layer. If unset, will be set to the layer name.
  • name – string or None. If set, gives the name of the layer. Otherwise, use _layer_{idx}, where idx specifies the layer index.
  • phase – int or None. If set, specifies the layer phase.
  • include_phasebarrista.design.Phase or None. Only include this layer in the given phase.
  • include_stages – string or None. Only include this layer if all stages are present.
  • include_min_level – int or None. Only include this layer, if the network level is >= this value.
  • include_max_level – int or None. Only include this layer, if the network level is <= this value.
  • params – list(barrista.design.ParamSpec) or None. Multipliers for learning rate and weight decay for the layer parameters.
  • propagate_down – list(bool) or None. Specifies on which bottoms the backpropagation should be skipped. Must be either 0 or equal to the number of bottoms. If None is specified, this is initialized as []. Not available in all caffe versions!
  • loss_parambarrista.design.LossParameter or None. Specifies optional ignore labels and normalization for the loss.
  • loss_weights – list(float) or None. The amount of weight to assign each top blob in the objective. If None is specified, this is initialized as [].
static from_pbuf_message(message)[source]

Create a LayerSpecification object from a protobuf message.

to_pbuf_message(layerindex, preceeding_layer, net_input)[source]

Create a protobuf specification of this layer.

It automatically wires together preceeding and following layers, if tops or bottoms are not set. This does not work with multiple in- or outputs.

Parameters:
  • layerindex – int >= 0. The index of this layer. Is used to generate the layer name.
  • preceeding_layerbarrista.design.LayerSpecification. The preceeding layer to create the wiring with.
  • net_input – string. The name of the network input (used for the first layer input).
barrista.design.LogLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Log_scale=None, Log_base=None, Log_shift=None)
barrista.design.MVNLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, MVN_across_channels=None, MVN_normalize_variance=None, MVN_eps=None)
barrista.design.MultinomialLogisticLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Loss_normalize=None, Loss_ignore_label=None, Loss_normalization=None)
class barrista.design.NetSpecification(input_shape, inputs=None, layers=None, force_backward=False, phase=None, level=0, stages=None, debug_info=False, name='DCNN', predict_inputs=None, predict_input_shapes=None)[source]

Bases: object

Represents a network specification.

Initializes the fields with similar semantics as the prototxt files. An important difference is, that if predict_inputs and predict_input_shapes are specified, this corresponds to two virtual network specifications. One, where the stage is set as specified by the stages parameter, and one where the stage is set to ‘predict’. Both networks share the same weights. When instantiated, the ‘predict’ network will automatically be used by the barrista.net.Net.predict() method.

graph network_stages_and_phases {
subgraph cluster_fit {
    phase_train_fit [label="phase: train"];
    phase_test_fit [label="phase: test"];
    label="stage: fit";
    graph[style=dotted];
}
subgraph cluster_predict {
    phase_test_predict [label="phase: test"];
    label="stage: predict";
    graph[style=dotted];
}
}

To get the plain specification of the network in ‘predict’ mode, use the method barrista.design.NetSpecification.get_predict_net_specification().

Parameters:
  • input_shape – list(list(int)). The input shape specification of the network. The length of each of the sub-lists must be > 0.
  • inputs – list(string) or None. The names of the network inputs. The length must match the length of the input_shape list. If None is used, this is initialized as ['data'].
  • layers – list(barrista.design.LayerSpecification) or None. The layer specifications. If None is used, this is initialized as [].
  • force_backward – bool. Whether to force a backward pass for all layers only useful during training.
  • phasebarrista.design.Phase or None. The phase to have the network in. If it is None, it is set to either TRAIN if predict_inputs and predict_inputs_shapes is given, or TEST otherwise. Default: None.
  • level – int. The level of the network. Can be used to in- or exclude layers depending on the level.
  • stages – list(string) or None. The stages the network is in. Can be used to in- or exclude layers depending on the stages. By default, ‘fit’ and ‘predict’ stages are used, as mentioned before. If None is specified, this is initialized as ['fit'].
  • debug_info – bool. If set to True, give additional debug output on the console.
  • name – string. The name of the network.
  • predict_inputs – list(string) or None. If set, will be used as inputs for a network with the same specification, except stages=['predict']. This will then automatically used after instantiation for predicting inputs.
  • predict_input_shapes – list(list(int)) or None. If set, will be used together with predict_inputs as stated above.
copy()[source]

Create a deep copy of this object.

All layers are deep copied, so modifying layer objects of the old object does not influence the copied one!

static from_prototxt(text=None, filename=None)[source]

Create an NetSpecification object from a text spec.

Either text or filename may be set, and is accordingly used. Files may be of any caffe prototxt version.

get_predict_net_specification()[source]

Get the plain network specification with stages=['predict'].

instantiate()[source]

Create an instantiated net with the current object configuration.

to_pbuf_message(drop_phase=False)[source]

Create a plain protobuf message from this object.

Since this object is not derived from the protobuf objects, it is necessary to have this converter. Deriving is discouraged by the protobuf documentation and this object offers a lot more functionality.

Parameters:drop_phase – Bool. If set to True, phase, level and stage are not serialized. Default: False.
to_prototxt(output_filename=None, drop_phase=False)[source]

Create a plain, human readable, prototxt representation.

If output_filename is set, the resulting text is written into that file, as well as returned. Otherwise, only the text is returned.

Layers will be automatically wired together, if their bottoms or tops are not set. If the have multiple inputs or outputs, you will have to take care of that (there is no way of inferring the semantics then).

Parameters:
  • output_filename – String or None. A file to write the prototxt information to.
  • drop_phase – Bool. If set to True, phase, level and stage will not be serialized. Default: False.
visualize(layout_dir='LR', display=False)[source]

Create and optionally display an image of the net structure.

Parameters:
  • layout_dir – string in [‘LR’, ‘TB’, ‘BT’]. Short string for graph layout direction.
  • display – bool. If set to True, displays the graphic in a window. Press enter to close it.
Returns:

3D numpy array. Graphic of the visualization as (H, W, C) image in BGR format.

barrista.design.PROTODETAIL = <module 'caffe.proto.caffe_pb2' from '/is/ps2/classner/git/caffe/build/install/python/caffe/proto/caffe_pb2.pyc'>

Expose all detailed properties from the caffe prototxt for in-Python usage.

barrista.design.PReLULayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, PReLU_filler=None, PReLU_channel_shared=None)
barrista.design.Phase

Describes the phase a network is in (TRAIN or TEST). It may only be set when instantiating the network. If phase is TEST, some memory optimizations are done, that prohibit training the network. The other way around, it is no problem to test a network in TRAIN mode, but it will be less efficient.

alias of Enum

barrista.design.PoolingLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Pooling_stride_h=None, Pooling_stride_w=None, Pooling_stride=None, Pooling_pad=None, Pooling_global_pooling=None, Pooling_engine=None, Pooling_pad_h=None, Pooling_pad_w=None, Pooling_pool=None, Pooling_kernel_w=None, Pooling_kernel_h=None, Pooling_kernel_size=None)
barrista.design.PowerLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Power_scale=None, Power_power=None, Power_shift=None)
barrista.design.PythonLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Python_layer=None, Python_module=None, Python_param_str=None, Python_share_in_parallel=None)
barrista.design.ReLULayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, ReLU_negative_slope=None, ReLU_engine=None)
barrista.design.ReductionLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Reduction_operation=None, Reduction_axis=None, Reduction_coeff=None)
barrista.design.ResampleLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None)
barrista.design.ReshapeLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Reshape_axis=None, Reshape_num_axes=None, Reshape_shape=None)
barrista.design.SPPLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, SPP_engine=None, SPP_pool=None, SPP_pyramid_height=None)
barrista.design.ScaleLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Scale_bias_term=None, Scale_axis=None, Scale_bias_filler=None, Scale_filler=None, Scale_num_axes=None)
barrista.design.SigmoidCrossEntropyLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Loss_normalize=None, Loss_ignore_label=None, Loss_normalization=None)
barrista.design.SigmoidLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Sigmoid_engine=None)
barrista.design.SilenceLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None)
barrista.design.SliceLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Slice_axis=None, Slice_slice_dim=None, Slice_slice_point=None)
barrista.design.SoftmaxLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Softmax_axis=None, Softmax_engine=None)
barrista.design.SoftmaxWithLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Softmax_axis=None, Softmax_engine=None, Loss_normalize=None, Loss_ignore_label=None, Loss_normalization=None)
barrista.design.SplitLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None)
barrista.design.TanHLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, TanH_engine=None)
barrista.design.ThresholdLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Threshold_threshold=None)
barrista.design.VariableHingeLossLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, Loss_normalize=None, Loss_ignore_label=None, Loss_normalization=None)
barrista.design.WindowDataLayer(bottoms=None, tops=None, name=None, phase=None, include_phase=None, include_stages=None, include_min_level=None, include_max_level=None, params=None, propagate_down=None, loss_param=None, loss_weights=None, WindowData_fg_fraction=None, WindowData_mirror=None, WindowData_cache_images=None, WindowData_crop_size=None, WindowData_scale=None, WindowData_root_folder=None, WindowData_source=None, WindowData_context_pad=None, WindowData_bg_threshold=None, WindowData_crop_mode=None, WindowData_batch_size=None, WindowData_mean_file=None, WindowData_fg_threshold=None)

barrista.initialization module

Initialization module.

Adds caffe to the pythonpath when imported. Any changes of config objects must be done before the import. Any imports of caffe related objects may only be done after.

barrista.initialization.init()[source]

Empty at the moment.

barrista.monitoring module

Defines several tools for monitoring net activity.

class barrista.monitoring.ActivationMonitor(write_every, output_folder, selected_blobs=None, iteroffset=0, sample=None, create_videos=True, video_frame_rate=1)[source]

Bases: barrista.monitoring.Monitor

Tools to keep an eye on the net activations.

Create plots of the net activations. If create_videos is set and ffmpeg is available, automatically creates videos.

Parameters:
  • write_every – int. Write every x iterations. Since matplotlib takes some time to run, choose with care.
  • output_folder – string. Where to store the outputs.
  • selected_blobs – list(string) or None. Which blobs to include in the plots. If None, then all parameters are plotted. Default: None.
  • iteroffset – int. An iteration offset if training is resumed to not overwrite existing output. Default: 0.
  • sample – dict(string, NDarray(3D)). A sample to use that will be forward propagated to obtain the activations. Must contain one for every input layer of the network. Each sample is not preprocessed and must fit the input. If None, use the existing values from the blobs.
  • create_videos – Bool. If set to True, try to create a video using ffmpeg. Default: True.
  • video_frame_rate – int. The video frame rate.
finalize(kwargs)[source]
class barrista.monitoring.Checkpointer(name_prefix, iterations, base_iterations=0)[source]

Bases: barrista.monitoring.Monitor

Writes the network blobs to disk at certain iteration intervals.

The logger makes use of the following keyword arguments (* indicates required):

  • iter*,
  • net*,
  • batch_size*.
Parameters:
  • name_prefix

    string or None. The first part of the output filenames to generate. The prefix ‘_iter_, the current iteration, as well as ‘.caffemodel’ is added.

    If you are using a caffe version from later than Dec. 2015, caffe’s internal snapshot method is exposed to Python and also snapshots the solver. If it’s available, then this method will be used. However, in that case, it’s not possible to influence the storage location from Python. Please use the solver parameter snapshot_prefix when constructing the solver instead (this parameter may be None and is unused then).

  • iterations – int > 0. Always if the current number of iterations is divisible by iterations, the network blobs are written to disk. Hence, this value must be a multiple of the batch size!
finalize(kwargs)[source]

Write a final checkpoint.

class barrista.monitoring.CyclingDataMonitor(X, only_preload=None, input_processing_flags=None, virtual_batch_size=None, color_data_augmentation_sigmas=None, shuffle=False)[source]

Bases: barrista.monitoring.DataMonitor, barrista.monitoring.ParallelMonitor

Uses the data sequentially.

This monitor maps data to the network an cycles through the data sequentially. It is the default monitor used if a user provides X or X_val to the barrista.solver.fit method.

If further processing of the original data is intended, by using the flag only_preload, the following monitors find a dictionary of lists of the original datapoints with the name ‘data_orig’ in their kwargs. The data is in this case NOT written to the network input layers! This can make sense, e.g., for the ResizingMonitor.

Parameters:
  • X – dict of numpy.ndarray or list, or None. If specified, is used as input data. It is used sequentially, so shuffle it pre, if required. The keys of the dict must have a corresponding layer name in the net. The values must be provided already in network dimension order, i.e., usually channels, height, width.
  • only_preload – list(string). List of blobs for which the data will be loaded and stored in a dict of (name: list) for further processing with other monitors.
  • input_processing_flags

    dict(string, string). Dictionary associating input blob names with intended preprocessing methods. Valid values are:

    • n: none,
    • rn: resize, nearest neighbour,
    • rc: resize, cubic,
    • rl: resize, linear,
    • pX: padding, with value X.
  • virtual_batch_size – int or None. Override the network batch size. May only be used if only_preload is set to True. Only makes sense with another DataMonitor in succession.
  • color_data_augmentation_sigmas – dict(string, float) or None. Enhance the color of the samples as described in (Krizhevsky et al., 2012). The parameter gives the sigma for the normal distribution that is sampled to obtain the weights for scaled pixel principal components per blob.
  • shuffle – Bool. If set to True, shuffle the data every epoch. Default: False.
get_parallel_blob_names()[source]
class barrista.monitoring.DataMonitor[source]

Bases: barrista.monitoring.Monitor

Monitor interface for filling the blobs of a network.

This is a specific monitor which will fill the blobs of the network for the forward pass or solver step. Ideally, there should only be one such monitor per callback, but multiple ones are possible.

class barrista.monitoring.FilterMonitor(write_every, output_folder, selected_parameters=None, iteroffset=0, create_videos=True, video_frame_rate=1)[source]

Bases: barrista.monitoring.Monitor

Tools to keep an eye on the filters.

Create plots of the network filters. Creates filter plots for all selected_parameters. If create_videos is set and ffmpeg is available, automatically creates videos.

Parameters:
  • write_every – int. Write every x iterations. Since matplotlib takes some time to run, choose with care.
  • output_folder – string. Where to store the outputs.
  • selected_parameters – dict(string, list(int)) or None. Which parameters to include in the plots. The string is the name of the layer, the list of integers contains the parts to include, e.g., for a convolution layer, specify the name of the layer as key and 0 for the parameters of the convolution weights, 1 for the biases per channel. The order and meaning of parameter blobs is determined by caffe. If None, then all parameters are plotted. Only 4D blobs can be plotted! Default: None.
  • iteroffset – int. An iteration offset if training is resumed to not overwrite existing output. Default: 0.
  • create_videos – Bool. If set to True, try to create a video using ffmpeg. Default: True.
  • video_frame_rate – int. The video frame rate.
finalize(kwargs)[source]
class barrista.monitoring.GradientMonitor(write_every, output_folder, selected_parameters=None, relative=False, iteroffset=0, create_videos=True, video_frame_rate=1)[source]

Bases: barrista.monitoring.Monitor

Tools to keep an eye on the gradient.

Create plots of the gradient. Creates histograms of the gradient for all selected_parameters and creates an overview plot with the maximum absolute gradient per layer. If create_videos is set and ffmpeg is available, automatically creates videos.

Parameters:
  • write_every – int. Write every x iterations. Since matplotlib takes some time to run, choose with care.
  • output_folder – string. Where to store the outputs.
  • selected_parameters – dict(string, list(int)) or None. Which parameters to include in the plots. The string is the name of the layer, the list of integers contains the parts to include, e.g., for a convolution layer, specify the name of the layer as key and 0 for the parameters of the convolution weights, 1 for the biases per channel. The order and meaning of parameter blobs is determined by caffe. If None, then all parameters are plotted. Default: None.
  • relative – Bool. If set to True, will give the weights relative to the max absolute weight in the target parameter blob. Default: False.
  • iteroffset – int. An iteration offset if training is resumed to not overwrite existing output. Default: 0.
  • create_videos – Bool. If set to True, try to create a video using ffmpeg. Default: True.
  • video_frame_rate – int. The video frame rate.
finalize(kwargs)[source]
class barrista.monitoring.JSONLogger(path, name, logging, base_iter=None, write_every=None, create_plot=False)[source]

Bases: barrista.monitoring.Monitor

Logs available information to a JSON file.

The information is stored in a dictionary of lists. The lists contain score information and the iteration at which it was obtained. The currently logged scores are loss, accuracy, test loss and test accuracy.

The logger makes use of the following keyword arguments (* indicates required):

  • iter*,
Parameters:
  • path – string. The path to store the file in.
  • name – string. The filename. Will be prefixed with ‘barrista_‘ and ‘.json’ will be appended.
  • logging – dict of lists. The two keys in the dict which are used are test, train. For each of those a list of keys can be provided, those keys have to be available in the kwargs/cbparams structure. Usually the required data is provided by the ResultExtractor.
  • base_iter – int or None. If provided, add this value to the number of iterations. This overrides the number of iterations retrieved from a loaded JSON log to append to.
  • write_every – int or None. Write the JSON log every write_every iterations. The log is always written upon completion of the training. If it is None, the log is only written on completion.
  • create_plot – bool. If set to True, create a plot at path when the JSON log is written with the name of the JSON file + _plot.png. Default: False.
finalize(kwargs)[source]

Write the json file.

class barrista.monitoring.Monitor[source]

Bases: object

The monitor interface.

Should be implemented by any monitor class. The method barrista.monitoring.Monitor.__call__() must be specified, the function barrista.monitoring.Monitor.finalize() may optionally be specified.

finalize(kwargs)[source]

Will be called at the end of a training/fitting process.

class barrista.monitoring.OversamplingDataMonitor(blobinfos, before_oversample_resize_to=None)[source]

Bases: barrista.monitoring.DataMonitor, barrista.monitoring.ParallelMonitor

Provides oversampled data.

Parameters:
  • blobinfos – dict(string, string|None). Associates blob name to oversample and optional the interpolation method to use for resize. This may be ‘n’ (nearest neighbour), ‘c’ (cubic), ‘l’ (linear) or None (no interpolation). If an interpolation method is selected, before_oversample_resize_to must be not None and provide a size.
  • before_oversample_resize_to – dict(string, 2-tuple). Specifies a size to which the image inputs will be resized before the oversampling is invoked.
get_parallel_blob_names()[source]

Get the names of all blobs that must be provided for the dummy.

class barrista.monitoring.ParallelMonitor[source]

Bases: barrista.monitoring.Monitor

Monitor interface for monitors executed parallel to processing a batch.

The order of all monitors implementing this interface is respected. They will work on a dummy network object with dummy blobs and prepare their data. The dummy blob content is then copied to the real network prior to the next batch execution.

get_parallel_blob_names()[source]

Get the names of all blobs that must be provided for the dummy.

class barrista.monitoring.ProgressIndicator[source]

Bases: barrista.monitoring.Monitor

Generates a progress bar with current information about the process.

The progress bar always displays completion percentage and ETA. If available, it also displays loss, accuracy, test loss and test accuracy.

It makes use of the following keyword arguments (* indicates required):

  • iter*,
  • max_iter*,
  • train_loss,
  • test_loss,
  • train_accuracy,
  • test_accuracy.
finalize(kwargs)[source]

Call progressbar.finish().

class barrista.monitoring.ResizingMonitor(blobinfos, base_scale=1.0, random_change_up_to=0.0, net_input_size_adjustment_multiple_of=0, interp_methods=None)[source]

Bases: barrista.monitoring.ParallelMonitor, barrista.monitoring.Monitor

Optionally resizes input data and adjusts the network input shape.

This monitor optionally resizes the input data randomly and adjusts the network input size accordingly (this works only for batch size 1 and fully convolutional networks).

For this to work, it must be used with the CyclingDataMonitor with only_preload set.

Parameters:
  • blobinfos – dict(string, int). Describes which blobs to apply the resizing operation to, and which padding value to use for the remaining space.
  • base_scale – float. If set to a value different than 1., apply the given base scale first to images. If set to a value different than 1., the parameter interp_methods must be set.
  • random_change_up_to – float. If set to a value different than 0., the scale change is altered randomly with a uniformly drawn value from -random_change_up_to to random_change_up_to, that is being added to the base value.
  • net_input_size_adjustment_multiple_of – int. If set to a value greater than 0, the blobs shape is adjusted from its initial value (which is used as minimal one) in multiples of the given one.
  • interp_methods – dict(string, string). Dictionary which stores for every blob the interpolation method. The string must be for each blob in [‘n’, ‘c’, ‘l’] (nearest neighbour, cubic, linear).
get_parallel_blob_names()[source]

Get the names of all blobs that must be provided for the dummy.

class barrista.monitoring.ResultExtractor(cbparam_key, layer_name)[source]

Bases: barrista.monitoring.Monitor

This monitor is designed for monitoring scalar layer results.

The main use case are salar outputs such as loss and accuracy.

IMPORTANT: this monitor will change cbparams and add new values to it, most likely other monitors will depend on this, thus, ResultExtractors should be among the first monitors in the callback list, e.g. by insert them always in the beginning.

It will extract the value of a layer and add the value to the cbparam.

Parameters:
  • cbparam_key – string. The key we will overwrite/set in the cbparams dict.
  • layer_name – string. The layer to extract the value from.
class barrista.monitoring.RotatingMirroringMonitor(blobinfos, max_rotation_degrees, mirror_prob=0.0, mirror_value_swaps=None, mirror_layer_swaps=None)[source]

Bases: barrista.monitoring.ParallelMonitor, barrista.monitoring.Monitor

Rotate and/or horizontally mirror samples within blobs.

For every sample, the rotation and mirroring will be consistent across the blobs.

Parameters:
  • blobinfos – dict(string, int). A dictionary containing the blob names and the padding values that will be applied.
  • max_rotation_degrees – float. The rotation will be sampled uniformly from the interval [-rotation_degrees, rotation_degrees[ for each sample.
  • mirror_prob – float. The probability that horizontal mirroring occurs. Is as well sampled individually for every sample.
  • mirror_value_swaps – dict(string, dict(int, list(2-tuples))). Specifies for every blob for every layer whether any values must be swapped if mirroring is applied. This is important when, e.g., mirroring annotation maps with left-right information. Every 2-tuple contains (original value, new value). The locations of the swaps are determined before any change is applied, so the order of tuples does not play a role.
  • mirror_layer_swaps – dict(string, list(2-tuples)). Specifies for every blob whether any layers must be swapped if mirroring is applied. Can be used together with mirror_value_swaps: in this case, the mirror_value_swaps are applied first, then the layers are swapped.
get_parallel_blob_names()[source]

Get the names of all blobs that must be provided for the dummy.

class barrista.monitoring.StaticDataMonitor(X)[source]

Bases: barrista.monitoring.DataMonitor, barrista.monitoring.ParallelMonitor

Always provides the same data for a specific net input blob.

Parameters:X – dict(string, np.ndarray) The static input blobs to use.
get_parallel_blob_names()[source]

Get the names of all blobs that must be provided for the dummy.

barrista.net module

Implements an extended Net object.

class barrista.net.Net(specification_filename, mode, specification=None)[source]

Bases: caffe._caffe.Net

An extended Net specification.

mode specifies the network mode. May be caffe.TRAIN or caffe.TEST. If set to caffe.TRAIN, training is possible, but forward propagation is slower and the network is less space efficient than when using caffe.TEST.

Parameters:
  • specification_filename – string. The network specification .prototxt file to use.
  • modebarrista.design.Phase. The phase to use for this network.
  • specificationbarrista.design.NetSpecification or None. The specification of this network. This cannot be derived solely from the .prototxt specification_filename, since this class can express more than the caffe protobuf supports. If this is not None, and the specification defines predict_inputs and predict_input_shapes, this internally generates a second network with the according inputs in stage predict (with shared weights) and uses it when calling the barrista.net.Net.predict() method.
fit(iterations, solver, X=None, X_val=None, input_processing_flags=None, test_iterations=0, test_interval=0, test_initialization=False, train_callbacks=None, test_callbacks=None, read_input_batch_size_from_blob_name=None, use_fit_phase_for_validation=False, allow_test_phase_for_train=False, shuffle=False)[source]

See barrista.solver.SolverInterface.fit().

load_blobs_from(filename)[source]

Load the network weights from the specified file.

Parameters:filename – string. The filename of the file to load.
predict(input_sequence=None, test_callbacks=None, out_blob_names=None, use_fit_network=None, oversample=False, before_oversample_resize_to=None, input_processing_flags=None, output_processing_flags=None, static_inputs=None, input_size_spec=None, allow_train_phase_for_test=False, net_input_size_adjustment_multiple_of=0)[source]

Predict samples in the spirit of scikit-learn. * It is YOUR responsibility to prepare the data in an iterable object

of numpy arrays with the correctly matching first dimension (i.e., the number of channels).
  • The method will match the data to the input size of the network and forward propagate it in batches.
Parameters:
  • input_sequence – iterable(3D numpy arrays) or dict(string: ...) or None. The 3D numpy arrays must match in their first dimension with the second dimension of the network input (number of channels). E.g., for a network with input shape [10, 3, 24, 24], you could provide inputs as 4D numpy array of shape [100, 3, 10, 10] or a list of 3D numpy arrays of shape [3, Y, X], where X and Y may be arbitrary and different for each image. If you are using a multi-input network, you can provide a dictionary of iterables of 3D numpy arrays before, where the keys are the input blob names to fill. Use the input_processing_flags to specify how preprocessing is done in any scenario. If the input sequence is None, you must provide a DataMonitor with the callbacks to fill the net inputs.
  • test_callbacks – list(barrista.monitoring.Monitor) or None. List of callback callables. Will be called pre and post batch processing. This list will be processed sequentially, meaning that monitors in the sequence can provide information for later monitors as done with the ResultExtractor.
  • out_blob_names – list(string) or None. The names of the blobs of which the values are returned. If unspecified, uses self.outputs.
  • use_fit_network – bool. If set to True, always use this very network, independent of whether an internal network in stage predict is available. For more information, see the constructor documentation.
  • oversample – bool. If set to True, uses oversampling and averages the results. You have to take care to bring them into the right shape for further processing yourself.
  • before_oversample_resize_to – 2-tuple(int) or None. A tuple specifying height and width to resize to before oversampling or None if the image should not be resized before oversampling.
  • input_processing_flags – dict(string:string) or None. A list or tuple of letters specifying the preprocessing for each input. ‘n’: no preprocessing, ‘rc’: rescale cubic, ‘rn’: rescale nearest, ‘rl’: rescale linear, ‘pX’: pad with value X. Default: [‘n’] * number_of_inputs
  • output_processing_flags – dict(string:string) or None. A list or tuple of letters specifying the postprocessing of the outputs. ‘n’: no postprocessing, ‘pX’: unpack from padding of input X, where X is the 0-based input index. Default: [‘n’] * number_of_inputs
  • static_inputs – list(string) or None. A list of input blob names for wich the input will always be fully used, independent of the selected samples.
  • input_size_spec – (int, int) or None. For exotic network configurations it can be necessary to specify the batch size and input size because it can not be automatically inferred. By default (None), use the first dimension of the first network blob as batch size and the first dimension of the associated inputs as amount of samples.
  • allow_train_phase_for_test – bool. If set to True, allow using a network in its TRAIN phase for prediction. May make sense in exotic settings, but should prevent bugs. If not set to True, an AssertionError is raised in this scenario. Why is this so important? The DropoutLayer and PoolLayer (in the case of stochastic pooling) are sensitive to this parameter and results are very different for the two settings.
  • net_input_size_adjustment_multiple_of – int. If set to a value>0, the networks input is resized in multiples of this value to take in the input images.
:returns : dict(string:np.array) or np.array.
Returns a dictionary of arrays if multiple outputs are returned or directly the array in the case of just one output.
predict_sliding_window(input_sequence, test_callbacks=None, out_blob_names=None, use_fit_network=False, oversample=False, extraction_step=(1, 1), account_for_step=True, interpolation_method=0L, pad_border=True, overlap_combine_max=True)[source]

Get predictions for all images in a sliding window manner.

Similar to the barrista.net.Net.predict() method. See there for the parameter descriptions. For this method, every image must be at least as big as the input size. It is then sampled using sliding window, and for each output layer the reassembled images are returned.

The output of the network for one patch must either be of shape (num_layers X 1 X 1) or of shape (num_layers X input_height X input_width) and currently only one output layer is supported. If the output is of the same shape as the input, account_for_step does not play a role, and the inputs are combined by using the max of the predictions per position.

Parameters:
  • input_sequence – iterable(3D numpy arrays) The 3D numpy arrays must match in their first dimension with the second dimension of the network input (number of channels). E.g., for a network with input shape [10, 3, 24, 24], you could provide inputs as 4D numpy array of shape [100, 3, 10, 10] or a list of 3D numpy arrays of shape [3, Y, X], where X and Y may be arbitrary and different for each image. Multi-input networks are not yet supported by this method.
  • test_callbacks – list(barrista.monitoring.Monitor) or None. List of callback callables. Will be called pre and post batch processing. This list will be processed sequentially, meaning that monitors in the sequence can provide information for later monitors as done with the ResultExtractor.
  • out_blob_names – list(string) or None. The names of the blobs of which the values are returned. If unspecified, uses self.outputs. Must currently contain exactly one element.
  • use_fit_network – bool. If set to True, always use this very network, independent of whether an internal network in stage predict is available. For more information, see the constructor documentation.
  • oversample – bool. If set to True, uses oversampling and averages the results. You have to take care to bring them into the right shape for further processing yourself.
  • extraction_step – 2-tuple(int). Window step size in y and x direction.
  • account_for_step – bool. If set to True, the output is resized with nearest neighbor interpolation to get a full-sized image.
  • interpolation_method – int in {cv2.INTER_...}. The interpolation strategy used, if account_for_step is set and the extraction_step is not (1, 1).
  • pad_border – bool. Whether to return images in the original image size, or by adding zero padded borders.
  • overlap_combine_max – bool. If the network output size is equal to the input size and the stepsize smaller than the output, which operator to use to combine overlapping areas. Default: True.
reshape_blob(name, *args)[source]

Reshape a blob for train and predict net variants.

Convenience method to reshape a blob for all network variants in use. Calls the caffe blob.reshape method internally. The blob must exist in both networks. To change a blob shape only in one variant, use net.blobs[name].reshape or net._predict_variant.blobs[name].reshape directly.

Parameters:
  • name – string. The name of the blob to reshape.
  • *args

    int. The shape-defining sizes.

visualize(layout_dir='LR', display=False)[source]

Visualize this model.

It must have a specification. It has one, if it is an instantiated barrista.design.NetSpecification, of if the parameter specification is set in the constructor.

Parameters:
  • layout_dir – string in [‘LR’, ‘TB’, ‘BT’]. Short string for graph layout direction.
  • display – bool. If set to True, displays the graphic in a window. Press enter to close it.
Returns:

3D numpy array. Graphic of the visualization as (H, W, C) image in BGR format.

barrista.net.set_device((int)arg1) → None :

Set id of GPU device.

barrista.net.set_mode_cpu() → None :

Set CPU processing mode.

barrista.net.set_mode_gpu() → None :

Set GPU processing mode.

barrista.solver module

Exposes the caffe solvers.

class barrista.solver.AdaDeltaSolver(**kwargs)[source]

Bases: barrista.solver.Solver

Thin wrapper for the AdaDelta solver provided by the caffe framework.

To understand how this solver works please inspect the cplusplus implementation in solver.cpp.

The corresponding arxiv paper is called ‘ADADELTA: An Adaptive Learning Rate Method’ by Matthew D. Zeiler.

Parameters:
  • delta – float numerical stability [useful choice 1E-8]
  • momentum – float or None. The momentum to use. Multiplies the former gradient with this factor and adds it to the gradient in the following step.
classmethod Get_optional_arguments()[source]

See barrista.solver.Solver.

classmethod Get_required_arguments()[source]

See barrista.solver.Solver.

class barrista.solver.AdagradSolver(**kwargs)[source]

Bases: barrista.solver.Solver

Thin wrapper for the Adagrad solver provided by the caffe framework.

To understand how this solver works please inspect the cplusplus implementation in solver.cpp.

The corresponding publication is called ‘Adaptive Subgradient Methods for Online Learning and Stochastic Optimization’ by John Duchi, Elad Hazan, Yoram Singer

Parameters:momentum – float or None. The momentum to use. Multiplies the former gradient with this factor and adds it to the gradient in the following step.
classmethod Get_optional_arguments()[source]

See barrista.solver.Solver.

classmethod Get_required_arguments()[source]

See barrista.solver.Solver.

class barrista.solver.AdamSolver(**kwargs)[source]

Bases: barrista.solver.Solver

Thin wrapper for the Adam solver provided by the caffe framework.

To understand how this solver works please inspect the cplusplus implementation in solver.cpp.

The corresponding arxiv paper is called ‘ Adam: A Method for Stochastic Optimization ‘ by Diederik Kingma, Jimmy Ba

Parameters:
  • base_lr – float [useful choice 0.001]
  • momentum – float. beta 1 useful default 0.9
  • momentum2 – float. beta 2 useful default 0.999
  • delta – float numerical stability [useful choice 1E-8]
classmethod Get_optional_arguments()[source]

See barrista.solver.Solver.

classmethod Get_required_arguments()[source]

See barrista.solver.Solver.

class barrista.solver.NesterovSolver(**kwargs)[source]

Bases: barrista.solver.Solver

Thin wrapper for the Nesterov solver provided by the caffe framework.

To understand how this solver works please inspect the cplusplus implementation in solver.cpp.

Parameters:momentum – float or None. The momentum to use. Multiplies the former gradient with this factor and adds it to the gradient in the following step.
classmethod Get_optional_arguments()[source]

See barrista.solver.Solver.

classmethod Get_required_arguments()[source]

See barrista.solver.Solver.

class barrista.solver.RMSPropSolver(**kwargs)[source]

Bases: barrista.solver.Solver

Thin wrapper for the RMSProp solver provided by the caffe framework.

To understand how this solver works please inspect the cplusplus implementation in solver.cpp.

This solver has been discussed in a lecture given by Hinton. www.cs.toronto.edu/~tijmen/csc321/slides/lecture_slides_lec6.pdf

Parameters:
  • rms_decay – float MeanSquare(t) = rms_decay*MeanSquare(t-1)+(1-rms_decay)*SquareGradient(t)
  • delta – float numerical stability [useful choice 1E-8]
classmethod Get_optional_arguments()[source]

See barrista.solver.Solver.

classmethod Get_required_arguments()[source]

See barrista.solver.Solver.

class barrista.solver.SGDSolver(**kwargs)[source]

Bases: barrista.solver.Solver

Thin wrapper for the vanilla SGD solver provided by the caffe framework.

Parameters:momentum – float or None. The momentum to use. Multiplies the former gradient with this factor and adds it to the gradient in the following step.
classmethod Get_optional_arguments()[source]

See barrista.solver.Solver.

classmethod Get_required_arguments()[source]

See barrista.solver.Solver.

class barrista.solver.Solver(**kwargs)[source]

Bases: object

Describes the Solver concept.

Assert_iter_size()[source]

Enforce the parameter constraints.

Assert_policy()[source]

Enforce the parameter constraints.

Assert_regularization_types()[source]

Enforce the parameter constraints.

classmethod Get_caffe_solver_class(caffe_solver_type)[source]

Get the solver class as caffe_solver_type.

classmethod Get_caffe_solver_instance(solver_parameter_dict, net)[source]

Get a caffe solver object.

classmethod Get_optional_arguments()[source]

Get the optional parameters.

Optional parameters and some of which are None not all combinations are possible, this is enforced by various asserts when calling Get_parameter_dict().

Get_parameter_dict()[source]

Get the solver describing parameters in a dictionary.

classmethod Get_parameter_hash(solver_parameter_dict)[source]

Get a has of the parameter dict.

classmethod Get_required_arguments()[source]

The minimum number of required parameters.

classmethod Get_solver_class(solver_type)[source]

Get the solver class as string.

classmethod Register_solver(solver_class)[source]

Register a solver class.

fit(iterations, X=None, X_val=None, input_processing_flags=None, test_iterations=0, test_interval=0, test_initialization=False, train_callbacks=None, test_callbacks=None, net=None, read_input_batch_size_from_blob_name=None, use_fit_phase_for_validation=False, allow_test_phase_for_train=False, shuffle=False)[source]

fit the network to specific data.

Use monitors from the module barrista.monitoring as callbacks to monitor the state of the net and create checkpoints. This method offers the following kwargs to monitors (* indicates, that the values are only available at test time, - indicates, that the value is not necessarily available):

  • max_iter,

  • iter,

  • batch_size,

  • net,

  • testnet[only if there is a test phase, i.e., X_val is set]

  • solver,

  • callback_signal[is automatically set by the fit function],

  • X-[only if provided by the user],

  • X_val-[only if provided by the user],

  • [the following fields are only set if the corresponding

    loss/accuracy layer exists for the train and/or test phase. It can also be set by providing a custom ResultExtractor]

  • loss-,

  • test_loss*,

  • accuracy-,

  • test_accuracy*-,

Parameters:
  • iterations – int. The number of training iterations to do. This is the plain number of iterations, completely disregarding the batch size, i.e., for iterations being 10 and batch_size being 10, just one batch is forward propagated.
  • X – dict of numpy.ndarray or None. If specified, is used as input data. It is used sequentially, so shuffle it pre, if required. The keys of the dict have to have a corresponding layer name in the net.
  • X_val – dict of numpy.ndarray or None. If specified and test_interval>0, it is used as input data. It is used sequentially, so shuffle it pre, if required. The keys of the dict have to have a corresponding layer name in the net.
  • input_processing_flags – dict(string, string) or None. See CyclingDataMonitor.__init__ for the input_processing_flags parameter. In short, if you specify your sample via list, you may specify for each blob, whether they should be padded ‘p’, or resized ‘r’ to match the network input size. If they fit perfectly, you may specify ‘n’ or omit the parameter and use None.
  • test_iterations – int. The number of test iterations to determine the validation score, if test_interval>0.
  • test_interval – int. The number of iterations between runs on the validation set. Is specified in plain iterations, disregarding batch size. Hence, it must be a multiple of the batch size.
  • test_initialization – bool. Whether to do a run on the validation set pre the training is started to get an initial score.
  • train_callbacks – list(barrista.monitoring.Monitor). List of callback callables. Will be called pre and post training batch is processed. This list will be processed sequentially, meaning that monitors in the sequence can provide information for later monitors as done with ResultExtractor.
  • test_callbacks – list(callable). List of callback callables. Will be called for pre and post testing and pre and post each batch of testing processed. This list will be processed sequentially, meaning that monitors in the sequence can provide information for later monitors as done with ResultExtractor.
  • read_input_batch_size_from_blob_name – string. The name of the layer to take the input batch size from (as the first dimension of its first blob). Must be specified if the network does not have explicit inputs (e.g., when trained from an LMDB).
  • use_fit_phase_for_validation – bool. If set to True, use do not change the phase of the net for running a validation step during training. This can be helpful to reduce memory consumption. This ignores the TEST phase of the net completely, but it’s not necessary to use it if the data is provided by the Python layers.
  • allow_test_phase_for_train – bool. If set to True, allow using a network in its TEST phase to be trained. May make sense in exotic settings, but should prevent bugs. If not set to True, an AssertionError is raised in this scenario. Why is this so important? The DropoutLayer and PoolLayer (in the case of stochastic pooling) are sensitive to this parameter and results are very different for the two settings.
  • shuffle – bool. If set to True, shuffle the training data every epoch. The test data is not shuffled. Default: False.
restore(filename, net=None)[source]

Restore the solverstate from a file.

step(number_of_batches)[source]

Run number_of_batches solver steps.

update_parameters(**kwargs)[source]

Update the solver parameters.

barrista.solver.SolverType

Describes the type of the solver used. All solver types supported by caffe are available.

alias of Enum

barrista.tools module

Implements some useful tools.

class barrista.tools.TemporaryDirectory(suffix='', prefix='tmp', dir=None)[source]

Bases: object

Create and return a temporary directory.

This has the same behavior as mkdtemp but can be used as a context manager. For example:

with TemporaryDirectory() as tmpdir:
...

Upon exiting the context, the directory and everything contained in it are removed.

Source: http://stackoverflow.com/questions/19296146/ tempfile-temporarydirectory-context-manager-in-python-2-7.

cleanup(_warn=False)[source]

Guarantee a cleaned up state.

barrista.tools.chunks(seq, size)[source]

Create chunks of size of seq.

See http://stackoverflow.com/questions/434287/ what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks.

barrista.tools.pad(image, input_dims, get_padding=False, val=0, pad_at_least=False)[source]

Pad an image with given scale to the appropriate dimensions.

The scaled image must fit into the input_dims, otherwise an exception is thrown!

Parameters:
  • image – 3D numpy array. The image to pad, as (C, H, W).
  • input_dims – tuple(int). A two-tuple of ints with the first value specifying height, the second width.
  • get_padding – bool. If set to True, returns a second value, which is a tuple of two-tuples, where each tuple contains the two values for left-right paddings for one of the image dimensions.
  • val – int. The value to pad with.
  • pad_at_least – bool. If set to True, allows input_dims that are smaller than the image size. Otherwise, it throws in this case.
Returns:

3D array, padded or, if get_padding, (3D array, tuple(two-tuples)).

barrista.tools.pbufToPyEnum(pbufenum)[source]

Helper function to create a Python enum out of a protobuf one.

Module contents

The barrista main module.