4.1. conx package¶
4.1.1. Submodules¶
4.1.2. conx.network module¶
The network module contains the code for the Network class.

class
conx.network.
FunctionCallback
(network, on_method, function)[source]¶ Bases:
keras.callbacks.Callback
‘on_batch_begin’, ‘on_batch_end’, ‘on_epoch_begin’, ‘on_epoch_end’, ‘on_train_begin’, ‘on_train_end’,

class
conx.network.
Network
(name: str, *sizes: int, **config: typing.Any)[source]¶ Bases:
object
The main class for the conx neural network package.
Parameters:  name – Required. The name of the network. Should not contain special HTML characters.
 sizes – Optional numbers. Defines the sizes of layers of a sequential network. These will be created, added, and connected automatically.
 config – Configuration overrides for the network.
Note
To create a complete, operating network, you must do the following items:
 create a network
 add layers
 connect the layers
 compile the network
 set the dataset
 train the network
See also
Layer
,Network.add
,Network.connect
, andNetwork.compile
.Examples
>>> net = Network("XOR1", 2, 5, 2) >>> len(net.layers) 3
>>> net = Network("XOR2") >>> net.add(Layer("input", 2)) >>> net.add(Layer("hidden", 5)) >>> net.add(Layer("output", 2)) >>> net.connect() >>> len(net.layers) 3
>>> net = Network("XOR3") >>> net.add(Layer("input", 2)) >>> net.add(Layer("hidden", 5)) >>> net.add(Layer("output", 2)) >>> net.connect("input", "hidden") >>> net.connect("hidden", "output") >>> len(net.layers) 3
>>> net = Network("NMIST") >>> net.name 'NMIST' >>> len(net.layers) 0
>>> net = Network("NMIST", 10, 5, 1) >>> len(net.layers) 3
>>> net = Network("NMIST", 10, 5, 5, 1, activation="sigmoid") >>> net.config["activation"] 'sigmoid' >>> net["output"].activation == "sigmoid" True >>> net["hidden1"].activation == "sigmoid" True >>> net["hidden2"].activation == "sigmoid" True >>> net["input"].activation is None True >>> net.layers[0].name == "input" True

ERROR_FUNCTIONS
= ['binary_crossentropy', 'categorical_crossentropy', 'categorical_hinge', 'cosine', 'cosine_proximity', 'hinge', 'kld', 'kullback_leibler_divergence', 'logcosh', 'mae', 'mape', 'mean_absolute_error', 'mean_absolute_percentage_error', 'mean_squared_error', 'mean_squared_logarithmic_error', 'mse', 'msle', 'poisson', 'sparse_categorical_crossentropy', 'squared_hinge']¶

OPTIMIZERS
= ('sgd', 'rmsprop', 'adagrad', 'adadelta', 'adam', 'adamax', 'nadam', 'tfoptimizer')¶

add
(layer: conx.layers.Layer) → None[source]¶ Add a layer to the network layer connections. Order is not important, unless calling
Network.connect
without any arguments.Parameters: layer – A layer instance. Examples
>>> net = Network("XOR2") >>> net.add(Layer("input", 2)) >>> len(net.layers) 1
>>> net = Network("XOR3") >>> net.add(Layer("input", 2)) >>> net.add(Layer("hidden", 5)) >>> net.add(Layer("output", 2)) >>> len(net.layers) 3
Note
See
Network
for more information.

build_svg
(inputs=None, class_id=None, opts={})[source]¶ opts  temporary override of config
 includes:
 “font_size”: 12, “border_top”: 25, “border_bottom”: 25, “hspace”: 100, “vspace”: 50, “image_maxdim”: 200 “image_pixels_per_unit”: 50
See .config for all options.

compile
(**kwargs)[source]¶ Check and compile the network.
See https://keras.io/ Model.compile() method for more details.

connect
(from_layer_name: str = None, to_layer_name: str = None)[source]¶ Connect two layers together if called with arguments. If called with no arguments, then it will make a sequential run through the layers in order added.
Parameters:  from_layer_name – Name of layer where connect begins.
 to_layer_name – Name of layer where connection ends.
 both from_layer_name and to_layer_name are None, then (If) –
 of the layers are connected sequentially in the order (all) –
 added. –
Examples
>>> net = Network("XOR2") >>> net.add(Layer("input", 2)) >>> net.add(Layer("hidden", 5)) >>> net.add(Layer("output", 2)) >>> net.connect() >>> [layer.name for layer in net["input"].outgoing_connections] ['hidden']

dashboard
(width='95%', height='550px', play_rate=0.5)[source]¶ Build the dashboard for Jupyter widgets. Requires running in a notebook/jupyterlab.

describe_connection_to
(layer1, layer2)[source]¶ Returns a textual description of the weights for the SVG tooltip.

display_component
(vector, component, **opts)[source]¶ vector is a list, one each per output layer. component is “errors” or “targets”

evaluate
(batch_size=32)[source]¶ Test the network on the train and test data, returning a dict of results.
Example
>>> net = Network("Evaluate", 2, 2, 1, activation="sigmoid") >>> net.compile(error='mean_squared_error', optimizer="adam") >>> ds = [[[0, 0], [0]], ... [[0, 1], [1]], ... [[1, 0], [1]], ... [[1, 1], [0]]] >>> net.dataset.load(ds) >>> net.evaluate() {'loss': ..., 'acc': ...}

from_array
(array: list)[source]¶ Load the weights from a list.
Parameters: array – a sequence (e.g., list, np.array) of numbers Example
>>> from conx import Network >>> net = Network("Deep", 3, 4, 5, 2, 3, 4, 5) >>> net.compile(optimizer="adam", error="mse") >>> net.from_array([0] * 103) >>> array = net.to_array() >>> len(array) 103

get_weights_from_history
(index, epochs=None)[source]¶ Get the weights of the network from a particular point in the learning sequence.
wts = net.get_weights_from_history(0) # get initial weights wts = net.get_weights_from_history(1) # get last weights
See also
 Network.set_weights_from_history

in_console
(mpl_backend: str) → bool[source]¶ Return True if running connected to a console; False if connected to notebook, or other nonconsole system.
 Possible values:
‘TkAgg’  console with Tk ‘Qt5Agg’  console with Qt ‘MacOSX’  mac console ‘module://ipykernel.pylab.backend_inline`  default for notebook
and nonconsole, and when using %matplotlib inline‘NbAgg`  notebook, using %matplotlib notebook
Here, None means not plotting, or just use text.
NOTE: if you are running ipython without a DISPLAY with the QT background, you may wish to:
export QT_QPA_PLATFORM=’offscreen’

load_history
(dir=None, filename=None)[source]¶ Load the history from a dir/file.
network.load_history()

load_weights
(dir=None, filename=None)[source]¶ Load the network weights and history from dir/files.
network.load_weights()

pf
(vector, **opts)[source]¶ Prettyformat a vector. Returns string.
Parameters:  vector (list) – The first parameter.
 precision (int) – Number of decimal places to show for each value in vector.
Returns: Returns the vector formatted as a short string.
Return type: Examples
These examples demonstrate the net.pf formatting function:
>>> import conx >>> net = Network("Test") >>> net.pf([1.01]) '[1.01]'
>>> net.pf(range(10), precision=2) '[0,1,2,3,4,5,6,7,8,9]'
>>> net.pf([0]*10000) '[0,0,0,..., 0,0,0]'

pf_matrix
(matrix, force=False, **opts)[source]¶ Prettyfromat a matrix. If a list, then that implies multibank.

playback
(function)[source]¶ Playback a function over the set of recorded weights.
function has signature: function(network, epoch)

plot
(metrics=None, ymin=None, ymax=None, start=0, end=None, legend='best', label=None, symbols=None, title=None, return_fig_ax=False, fig_ax=None, interactive=True)[source]¶ Plots the current network history for the specific epoch range and metrics. metrics is ‘?’, ‘all’, a metric keyword, or a list of metric keywords. if metrics is None, loss and accuracy are plotted on separate graphs.
>>> net = Network("Plot Test", 1, 3, 1) >>> net.compile(error="mse", optimizer="rmsprop") >>> net.dataset.add([0.0], [1.0]) >>> net.dataset.add([1.0], [0.0]) >>> net.train() Evaluating initial training metrics... Training... ... >>> net.plot('?') Available metrics: acc, loss

plot_activation_map
(from_layer='input', from_units=(0, 1), to_layer='output', to_unit=0, colormap=None, default_from_layer_value=0, resolution=None, act_range=(0, 1), show_values=False, title=None, interactive=True, scatter=None, symbols=None)[source]¶ Plot the activations at a bank/unit given two input units.

plot_layer_weights
(layer_name, units='all', wrange=None, wmin=None, wmax=None, cmap='gray', vshape=None, cbar=True, ticks=5, figsize=(12, 3), interactive=True)[source]¶ weight range displayed on the colorbar can be specified as wrange=(wmin, wmax), or individually via wmin/wmax keywords. if wmin or wmax is None, the actual min/max value of the weight matrix is used. wrange overrides provided wmin/wmax values. ticks is the number of colorbar ticks displayed. cbar=False turns off the colorbar. units can be a single unit index number or a list/tuple/range of indices.

plot_loss_acc
(callback, epoch, interactive=True)[source]¶ plots loss and accuracy on separate graphs, ignoring any other metrics

propagate
(input, batch_size=32, visualize=None)[source]¶ Propagate an input (in human API) through the network. If visualizing, the network image will be updated.

propagate_from
(layer_name, input, output_layer_names=None, batch_size=32, visualize=None)[source]¶ Propagate activations from the given layer name to the output layers.

propagate_to
(layer_name, inputs, batch_size=32, visualize=None)[source]¶ Computes activation at a layer. Sideeffect: updates visualized SVG.

propagate_to_features
(layer_name, inputs, cols=5, scale=1.0, html=True, size=None, display=True)[source]¶ if html is True, then generate HTML, otherwise send images.

propagate_to_image
(layer_name, input, batch_size=32, scale=1.0, visualize=None)[source]¶ Gets an image of activations at a layer.

reset
(clear=False, **overrides)[source]¶ Reset all of the weights/biases in a network. The magnitude is based on the size of the network.

retrain
(**overrides)[source]¶ Call network.train() again with same options as last call, unless overrides.

save_weights
(dir=None, filename=None)[source]¶ Save the network weights and history to dir/files.
network.save_weights()

set_weights_from_history
(index, epochs=None)[source]¶ Set the weights of the network from a particular point in the learning sequence.
net.set_weights_from_history(0) # restore initial weights net.set_weights_from_history(1) # restore last weights
See also
 Network.get_weights_from_history

snapshot
(inputs=None, class_id=None, height='780px', opts={})[source]¶ Create an SVG of the network given some inputs.
>>> net = Network("Snapshot", 2, 2, 1) >>> net.compile(error="mse", optimizer="adam") >>> net.snapshot([.5, .5]) <IPython.core.display.HTML object>

test
(batch_size=32, show=False, tolerance=None, force=False, show_inputs=True, show_outputs=True, filter='all', interactive=True)[source]¶ Test a dataset.

to_array
() → list[source]¶ Get the weights of a network as a flat, onedimensional list.
Example
>>> from conx import Network >>> net = Network("Deep", 3, 4, 5, 2, 3, 4, 5) >>> net.compile(optimizer="adam", error="mse") >>> array = net.to_array() >>> len(array) 103
Returns: All of weights and biases of the network in a single, flat list.

tolerance
¶

train
(epochs=1, accuracy=None, error=None, batch_size=32, report_rate=1, verbose=1, kverbose=0, shuffle=True, tolerance=None, class_weight=None, sample_weight=None, use_validation_to_stop=False, plot=False, record=0, callbacks=None)[source]¶ Train the network.
To stop before number of epochs, give either error=VALUE, or accuracy=VALUE.
Normally, it will check training info to stop, unless you use_validation_to_stop = True.

train_one
(inputs, targets, batch_size=32)[source]¶ Train on one input/target pair. Requires internal format.
Examples
>>> from conx import Network, Layer, SGD, Dataset >>> net = Network("XOR", 2, 2, 1, activation="sigmoid") >>> net.compile(error='mean_squared_error', ... optimizer=SGD(lr=0.3, momentum=0.9)) >>> ds = [[[0, 0], [0]], ... [[0, 1], [1]], ... [[1, 0], [1]], ... [[1, 1], [0]]] >>> net.dataset.load(ds) >>> out, err = net.train_one({"input": [0, 0]}, ... {"output": [0]}) >>> len(out) 1 >>> len(err) 1
>>> from conx import Network, Layer, SGD, Dataset >>> net = Network("XOR2") >>> net.add(Layer("input1", shape=1)) >>> net.add(Layer("input2", shape=1)) >>> net.add(Layer("hidden1", shape=2, activation="sigmoid")) >>> net.add(Layer("hidden2", shape=2, activation="sigmoid")) >>> net.add(Layer("sharedhidden", shape=2, activation="sigmoid")) >>> net.add(Layer("output1", shape=1, activation="sigmoid")) >>> net.add(Layer("output2", shape=1, activation="sigmoid")) >>> net.connect("input1", "hidden1") >>> net.connect("input2", "hidden2") >>> net.connect("hidden1", "sharedhidden") >>> net.connect("hidden2", "sharedhidden") >>> net.connect("sharedhidden", "output1") >>> net.connect("sharedhidden", "output2") >>> net.compile(error='mean_squared_error', ... optimizer=SGD(lr=0.3, momentum=0.9)) >>> ds = [([[0],[0]], [[0],[0]]), ... ([[0],[1]], [[1],[1]]), ... ([[1],[0]], [[1],[1]]), ... ([[1],[1]], [[0],[0]])] >>> net.dataset.load(ds) >>> net.compile(error='mean_squared_error', ... optimizer=SGD(lr=0.3, momentum=0.9)) >>> out, err = net.train_one({"input1": [0], "input2": [0]}, ... {"output1": [0], "output2": [0]}) >>> len(out) 2 >>> len(err) 2 >>> net.dataset._num_input_banks() 2 >>> net.dataset._num_target_banks() 2

class
conx.network.
PlotCallback
(network, report_rate, mpl_backend)[source]¶ Bases:
keras.callbacks.Callback
4.1.3. conx.dataset module¶
The Dataset class is useful for loading standard datasets, or for manipulating a set of inputs/targets.

class
conx.dataset.
DataVector
(dataset, item)[source]¶ Bases:
object
Class to make internal Keras numpy arrays look like lists in the [bank, bank, …] format.

flatten
(bank_index=None)[source]¶ >>> from conx import Network >>> net = Network("Test 2", 10, 2, 3, 28 * 28) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.add([0] * 10, [0] * 28 * 28) >>> net.dataset.targets.shape [(784,)] >>> net.dataset.targets.reshape(0, (28, 28)) >>> net.dataset.targets.shape [(28, 28)] >>> net.dataset.inputs.shape [(10,)] >>> net.dataset.inputs.reshape(0, (2, 5)) >>> net.dataset.inputs.shape [(2, 5)]

get_shape
(bank_index=None)[source]¶ Get the shape of the tensor at bank_index.
>>> from conx import Network, Layer >>> net = Network("Get Shape") >>> net.add(Layer("input1", 5)) >>> net.add(Layer("input2", 6)) >>> net.add(Layer("output", 3)) >>> net.connect("input1", "output") >>> net.connect("input2", "output") >>> net.compile(optimizer="adam", error="mse") >>> net.dataset.load([ ... ( ... [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0]], ... [0.5, 0.5, 0.5] ... ), ... ]) >>> net.dataset.inputs.get_shape() [(5,), (6,)] >>> net.dataset.inputs.get_shape(0) (5,) >>> net.dataset.inputs.get_shape(1) (6,) >>> net.dataset.targets.get_shape() [(3,)] >>> net.dataset.targets.get_shape(0) (3,) >>> net.dataset.inputs.shape [(5,), (6,)] >>> net.dataset.targets.shape [(3,)]

reshape
(bank_index, new_shape=None)[source]¶ Reshape the tensor at bank_index.
>>> from conx import Network >>> net = Network("Test 1", 10, 2, 3, 28 * 28) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.add([0] * 10, [0] * 28 * 28) >>> net.dataset.inputs.shape [(10,)] >>> net.dataset.inputs.reshape(0, (2, 5)) >>> net.dataset.inputs.shape [(2, 5)] >>> net.dataset.targets.shape [(784,)] >>> net.dataset.targets.reshape(0, (28, 28, 1)) >>> net.dataset.targets.shape [(28, 28, 1)] >>> net.dataset.targets.shape = (28 * 28,) >>> net.dataset.targets.shape [(784,)]

shape
¶ Get the shape of the tensor at bank_index.
>>> from conx import Network, Layer >>> net = Network("Get Shape") >>> net.add(Layer("input1", 5)) >>> net.add(Layer("input2", 6)) >>> net.add(Layer("output", 3)) >>> net.connect("input1", "output") >>> net.connect("input2", "output") >>> net.compile(optimizer="adam", error="mse") >>> net.dataset.load([ ... ( ... [[1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 0]], ... [0.5, 0.5, 0.5] ... ), ... ]) >>> net.dataset.inputs.get_shape() [(5,), (6,)] >>> net.dataset.inputs.get_shape(0) (5,) >>> net.dataset.inputs.get_shape(1) (6,) >>> net.dataset.targets.get_shape() [(3,)] >>> net.dataset.targets.get_shape(0) (3,) >>> net.dataset.inputs.shape [(5,), (6,)] >>> net.dataset.targets.shape [(3,)]


class
conx.dataset.
Dataset
(network=None, default_inputs=None, default_targets=None)[source]¶ Bases:
object
Contains the dataset, and metadata about it.
input_shapes = [shape, …] target_shapes = [shape, …]

add_by_function
(width, frange, ifunction, tfunction)[source]¶ width  length of an input vector frange  (start, stop) or (start, stop, step) ifunction  “onehot” or “binary” or callable(i, width) tfunction  a function given (i, input vector), return target vector
To add an AND problem:
>>> from conx import Network >>> net = Network("Test 1", 2, 2, 3, 1) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.add_by_function(2, (0, 4), "binary", lambda i,v: [int(sum(v) == len(v))]) >>> len(net.dataset.inputs) 4
Adds the following for inputs/targets: [0, 0], [0] [0, 1], [0] [1, 0], [0] [1, 1], [1]
>>> net = Network("Test 2", 10, 2, 3, 10) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.add_by_function(10, (0, 10), "onehot", lambda i,v: v) >>> len(net.dataset.inputs) 10
>>> import numpy as np >>> net = Network("Test 3", 10, 2, 3, 10) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.add_by_function(10, (0, 10), lambda i, width: np.random.rand(width), lambda i,v: v) >>> len(net.dataset.inputs) 10

chop
(retain=0.5)[source]¶ Chop off the inputs/targets and reset split, test data. Retains only the specified portion of the original dataset patterns, starting from the beginning. retain can be a fraction in the range 01, or an integer number of patterns to retain.

load
(pairs=None, inputs=None, targets=None, labels=None)[source]¶ Set the humanspecified dataset to a proper keras dataset.
Multiinputs or multitargets must be: [vector, vector, …] for each layer input/target pairing.
Note
If you have images in your dataset, they must match K.image_data_format().
See also
matrix_to_channels_last
andmatrix_to_channels_first
.

load_direct
(inputs=None, targets=None, labels=None)[source]¶ Set the inputs/targets in the specific internal format:
[[inputlayer1vectors, …], [inputlayer2vectors, …], …]
[[targetlayer1vectors, …], [targetlayer2vectors, …], …]

random
(length, frange=(1, 1))[source]¶ Append a number of random values in the range frange to inputs and targets.
>>> from conx import * >>> net = Network("Random", 5, 2, 3, 4) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.random(100) >>> len(net.dataset.inputs) 100 >>> len(net.dataset.targets) 100

set_inputs_from_targets
(f=None, input_bank=0, target_bank=0)[source]¶ Copy the targets to inputs. Optionally, apply a function f to target copy.
>>> from conx import Network >>> net = Network("Sample", 2, 2, 1) >>> ds = [[[0, 0], [0]], ... [[0, 1], [1]], ... [[1, 0], [1]], ... [[1, 1], [0]]] >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.load(ds) >>> net.dataset.set_inputs_from_targets(lambda tv: [tv[0], tv[0]]) >>> net.dataset.inputs[1] [1.0, 1.0]

set_targets_from_inputs
(f=None, input_bank=0, target_bank=0)[source]¶ Copy the inputs to targets. Optionally, apply a function f to input copy.
>>> from conx import Network >>> net = Network("Sample", 2, 2, 1) >>> ds = [[[0, 0], [0]], ... [[0, 1], [1]], ... [[1, 0], [1]], ... [[1, 1], [0]]] >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.load(ds) >>> net.dataset.set_targets_from_inputs(lambda iv: [iv[0]]) >>> net.dataset.targets[1] [0.0]

set_targets_from_labels
(num_classes=None, bank_index=0)[source]¶ Given net.labels are integers, set the net.targets to onehot() categories.

slice
(start=None, stop=None)[source]¶ Cut out some input/targets.
net.slice(100)  reduce to first 100 inputs/targets net.slice(100, 200)  reduce to second 100 inputs/targets

split
(split=0.5)[source]¶ Splits the inputs/targets into training and validation sets. The split keyword parameter specifies what portion of the dataset to use for validation. It can be a fraction in the range [0,1), or an integer number of patterns from 0 to the dataset size, or ‘all’. For example, a split of 0.25 reserves the last 1/4 of the dataset for validation. A split of 1.0 (specified as ‘all’ or an int equal to the dataset size) is a special case in which the entire dataset is used for both training and validation.

4.1.4. conx.layers module¶
The conx.layers module contains the code for all of the layers. In addition, it dynamically loads all of the Keras layers and wraps them as a conx layer.

class
conx.layers.
ActivationLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ActivationLayer
Applies an activation function to an output.
Arguments
 activation: name of activation function to use (see: activations), or alternatively, a Theano or TensorFlow operation.
Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as input.

CLASS
¶ alias of
Activation

class
conx.layers.
ActivityRegularizationLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ActivityRegularizationLayer
Layer that applies an update to the cost function based input activity.
Arguments
 l1: L1 regularization factor (positive float).
 l2: L2 regularization factor (positive float).
Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as input.

CLASS
¶ alias of
ActivityRegularization

class
conx.layers.
AddLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AddLayer
Layer that adds a list of inputs.
It takes as input a list of tensors,all of the same shape, and returnsa single tensor (also of the same shape).Examples
import keras input1 = keras.layers.Input(shape=(16,)) x1 = keras.layers.Dense(8, activation='relu')(input1) input2 = keras.layers.Input(shape=(32,)) x2 = keras.layers.Dense(8, activation='relu')(input2) added = keras.layers.Add()([x1, x2]) # equivalent to added = keras.layers.add([x1, x2]) out = keras.layers.Dense(4)(added) model = keras.models.Model(inputs=[input1, input2], outputs=out)

CLASS
¶ alias of
Add


class
conx.layers.
AlphaDropoutLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AlphaDropoutLayer
Applies Alpha Dropout to the input.
Alpha Dropout is aDropout
that keeps mean and variance of inputsto their original values, in order to ensure the selfnormalizing propertyeven after this dropout.Alpha Dropout fits well to Scaled Exponential Linear Unitsby randomly setting activations to the negative saturation value.Arguments
 rate: float, drop probability (as with
Dropout
). The multiplicative noise will have standard deviationsqrt(rate / (1  rate))
.  seed: A Python integer to use as random seed.
Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as input.
References

CLASS
¶ alias of
AlphaDropout
 rate: float, drop probability (as with

class
conx.layers.
AverageLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AverageLayer
Layer that averages a list of inputs.
It takes as input a list of tensors,all of the same shape, and returnsa single tensor (also of the same shape).
CLASS
¶ alias of
Average


class
conx.layers.
AveragePooling1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AveragePooling1DLayer
Average pooling for temporal data.
Arguments
 pool_size: Integer, size of the max pooling windows.
 strides: Integer, or None. Factor by which to downscale.
E.g. 2 will halve the input.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
3D tensor with shape:
(batch_size, downsampled_steps, features)
.
CLASS
¶ alias of
AveragePooling1D

class
conx.layers.
AveragePooling2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AveragePooling2DLayer
Average pooling operation for spatial data.
Arguments
 pool_size: integer or tuple of 2 integers, factors by which to downscale (vertical, horizontal). (2, 2) will halve the input in both spatial dimension. If only one integer is specified, the same window length will be used for both dimensions.
 strides: Integer, tuple of 2 integers, or None.
Strides values.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, pooled_rows, pooled_cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, pooled_rows, pooled_cols)

CLASS
¶ alias of
AveragePooling2D

class
conx.layers.
AveragePooling3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AveragePooling3DLayer
Average pooling operation for 3D data (spatial or spatiotemporal).
Arguments
 pool_size: tuple of 3 integers, factors by which to downscale (dim1, dim2, dim3). (2, 2, 2) will halve the size of the 3D input in each dimension.
 strides: tuple of 3 integers, or None. Strides values.
 padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)

CLASS
¶ alias of
AveragePooling3D

class
conx.layers.
AvgPool1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AvgPool1DLayer
Average pooling for temporal data.
Arguments
 pool_size: Integer, size of the max pooling windows.
 strides: Integer, or None. Factor by which to downscale.
E.g. 2 will halve the input.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
3D tensor with shape:
(batch_size, downsampled_steps, features)
.
CLASS
¶ alias of
AveragePooling1D

class
conx.layers.
AvgPool2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AvgPool2DLayer
Average pooling operation for spatial data.
Arguments
 pool_size: integer or tuple of 2 integers, factors by which to downscale (vertical, horizontal). (2, 2) will halve the input in both spatial dimension. If only one integer is specified, the same window length will be used for both dimensions.
 strides: Integer, tuple of 2 integers, or None.
Strides values.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, pooled_rows, pooled_cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, pooled_rows, pooled_cols)

CLASS
¶ alias of
AveragePooling2D

class
conx.layers.
AvgPool3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
AvgPool3DLayer
Average pooling operation for 3D data (spatial or spatiotemporal).
Arguments
 pool_size: tuple of 3 integers, factors by which to downscale (dim1, dim2, dim3). (2, 2, 2) will halve the size of the 3D input in each dimension.
 strides: tuple of 3 integers, or None. Strides values.
 padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)

CLASS
¶ alias of
AveragePooling3D

class
conx.layers.
BatchNormalizationLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
BatchNormalizationLayer
Batch normalization layer (Ioffe and Szegedy, 2014).
Normalize the activations of the previous layer at each batch,i.e. applies a transformation that maintains the mean activationclose to 0 and the activation standard deviation close to 1.Arguments
 axis: Integer, the axis that should be normalized
(typically the features axis).
For instance, after a
Conv2D
layer withdata_format="channels_first"
, setaxis=1
inBatchNormalization
.  momentum: Momentum for the moving average.
 epsilon: Small float added to variance to avoid dividing by zero.
 center: If True, add offset of
beta
to normalized tensor. If False,beta
is ignored.  scale: If True, multiply by
gamma
. If False,gamma
is not used. When the next layer is linear (also e.g.nn.relu
), this can be disabled since the scaling will be done by the next layer.  beta_initializer: Initializer for the beta weight.
 gamma_initializer: Initializer for the gamma weight.
 moving_mean_initializer: Initializer for the moving mean.
 moving_variance_initializer: Initializer for the moving variance.
 beta_regularizer: Optional regularizer for the beta weight.
 gamma_regularizer: Optional regularizer for the gamma weight.
 beta_constraint: Optional constraint for the beta weight.
 gamma_constraint: Optional constraint for the gamma weight.
Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as input.
References

CLASS
¶ alias of
BatchNormalization
 axis: Integer, the axis that should be normalized
(typically the features axis).
For instance, after a

class
conx.layers.
BidirectionalLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
BidirectionalLayer
Bidirectional wrapper for RNNs.
Arguments
 layer:
Recurrent
instance.  merge_mode: Mode by which outputs of the forward and backward RNNs will be combined. One of {‘sum’, ‘mul’, ‘concat’, ‘ave’, None}. If None, the outputs will not be combined, they will be returned as a list.
Raises
 ValueError: In case of invalid
merge_mode
argument.
Examples
model = Sequential() model.add(Bidirectional(LSTM(10, return_sequences=True), input_shape=(5, 10))) model.add(Bidirectional(LSTM(10))) model.add(Dense(5)) model.add(Activation('softmax')) model.compile(loss='categorical_crossentropy', optimizer='rmsprop')

CLASS
¶ alias of
Bidirectional
 layer:

class
conx.layers.
ConcatenateLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ConcatenateLayer
Layer that concatenates a list of inputs.
It takes as input a list of tensors,all of the same shape except for the concatenation axis,and returns a single tensor, the concatenation of all inputs.Arguments
 axis: Axis along which to concatenate.
 __**kwargs__: standard layer keyword arguments.

CLASS
¶ alias of
Concatenate

class
conx.layers.
Conv1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Conv1DLayer
1D convolution layer (e.g. temporal convolution).
This layer creates a convolution kernel that is convolvedwith the layer input over a single spatial (or temporal) dimensionto produce a tensor of outputs.Ifuse_bias
is True, a bias vector is created and added to the outputs.Finally, ifactivation
is notNone
,it is applied to the outputs as well.When using this layer as the first layer in a model,provide aninput_shape
argument(tuple of integers orNone
, e.g.(10, 128)
for sequences of 10 vectors of 128dimensional vectors,or(None, 128)
for variablelength sequences of 128dimensional vectors.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of a single integer, specifying the length of the 1D convolution window.
 strides: An integer or tuple/list of a single integer,
specifying the stride length of the convolution.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: One of
"valid"
,"causal"
or"same"
(caseinsensitive)."valid"
means “no padding”."same"
results in padding the input such that the output has the same length as the original input."causal"
results in causal (dilated) convolutions, e.g. output[t] does not depend on input[t+1:]. Useful when modeling temporal data where the model should not violate the temporal order. See WaveNet: A Generative Model for Raw Audio, section 2.1.  dilation_rate: an integer or tuple/list of a single integer,
specifying
the dilation rate to use for dilated convolution.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying anystrides
value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
3D tensor with shape:
(batch_size, steps, input_dim)
Output shape
3D tensor with shape:(batch_size, new_steps, filters)
steps
value might have changed due to padding or strides.
CLASS
¶ alias of
Conv1D

class
conx.layers.
Conv2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Conv2DLayer
2D convolution layer (e.g. spatial convolution over images).
This layer creates a convolution kernel that is convolvedwith the layer input to produce a tensor ofoutputs. Ifuse_bias
is True,a bias vector is created and added to the outputs. Finally, ifactivation
is notNone
, it is applied to the outputs as well.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 3)
for 128x128 RGB picturesindata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 2 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(samples, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(samples, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(samples, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(samples, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.
CLASS
¶ alias of
Conv2D

class
conx.layers.
Conv2DTransposeLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Conv2DTransposeLayer
Transposed convolution layer (sometimes called Deconvolution).
The need for transposed convolutions generally arisesfrom the desire to use a transformation going in the opposite directionof a normal convolution, i.e., from something that has the shape of theoutput of some convolution to something that has the shape of its inputwhile maintaining a connectivity pattern that is compatible withsaid convolution.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 3)
for 128x128 RGB picturesindata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 2 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(batch, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(batch, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.References

CLASS
¶ alias of
Conv2DTranspose

class
conx.layers.
Conv3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Conv3DLayer
3D convolution layer (e.g. spatial convolution over volumes).
This layer creates a convolution kernel that is convolvedwith the layer input to produce a tensor ofoutputs. Ifuse_bias
is True,a bias vector is created and added to the outputs. Finally, ifactivation
is notNone
, it is applied to the outputs as well.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 128, 1)
for 128x128x128 volumeswith a single channel,indata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of 3 integers, specifying the depth, height and width of the 3D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 3 integers,
specifying the strides of the convolution along each spatial
dimension.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 3 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
5D tensor with shape:(samples, channels, conv_dim1, conv_dim2, conv_dim3)
if data_format=’channels_first’or 5D tensor with shape:(samples, conv_dim1, conv_dim2, conv_dim3, channels)
if data_format=’channels_last’.Output shape
5D tensor with shape:(samples, filters, new_conv_dim1, new_conv_dim2, new_conv_dim3)
if data_format=’channels_first’or 5D tensor with shape:(samples, new_conv_dim1, new_conv_dim2, new_conv_dim3, filters)
if data_format=’channels_last’.new_conv_dim1
,new_conv_dim2
andnew_conv_dim3
values might have changed due to padding.
CLASS
¶ alias of
Conv3D

class
conx.layers.
Conv3DTransposeLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Conv3DTransposeLayer
Transposed convolution layer (sometimes called Deconvolution).
The need for transposed convolutions generally arisesfrom the desire to use a transformation going in the opposite directionof a normal convolution, i.e., from something that has the shape of theoutput of some convolution to something that has the shape of its inputwhile maintaining a connectivity pattern that is compatible withsaid convolution.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 128, 3)
for a 128x128x128 volume with 3 channelsifdata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).
 kernel_size: An integer or tuple/list of 3 integers, specifying the width and height of the 3D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 3 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, depth, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, depth, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 3 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
5D tensor with shape:(batch, channels, depth, rows, cols)
if data_format=’channels_first’or 5D tensor with shape:(batch, depth, rows, cols, channels)
if data_format=’channels_last’.Output shape
5D tensor with shape:(batch, filters, new_depth, new_rows, new_cols)
if data_format=’channels_first’or 5D tensor with shape:(batch, new_depth, new_rows, new_cols, filters)
if data_format=’channels_last’.depth
androws
andcols
values might have changed due to padding.References

CLASS
¶ alias of
Conv3DTranspose

class
conx.layers.
ConvLSTM2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ConvLSTM2DLayer
Convolutional LSTM.
It is similar to an LSTM layer, but the input transformationsand recurrent transformations are both convolutional.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of n integers, specifying the dimensions of the convolution window.
 strides: An integer or tuple/list of n integers,
specifying the strides of the convolution.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, time, ..., channels)
whilechannels_first
corresponds to inputs with shape(batch, time, channels, ...)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: An integer or tuple/list of n integers,
specifying
the dilation rate to use for dilated convolution.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying anystrides
value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  recurrent_activation: Activation function to use for the recurrent step (see activations).
 use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 unit_forget_bias: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Use in combination with
bias_initializer="zeros"
. This is recommended in Jozefowicz et al.  kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 return_sequences: Boolean. Whether to return the last output in the output sequence, or the full sequence.
 go_backwards: Boolean (default False). If True, rocess the input sequence backwards.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.
 dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
 recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.
Input shape
 if data_format=’channels_first’
5D tensor with shape:
(samples,time, channels, rows, cols)
 if data_format=’channels_last’
5D tensor with shape:
(samples,time, rows, cols, channels)
# Output shape
 if
return_sequences
 if data_format=’channels_first’
5D tensor with shape:
(samples, time, filters, output_row, output_col)
 if data_format=’channels_last’
5D tensor with shape:
(samples, time, output_row, output_col, filters)
 if data_format=’channels_first’
5D tensor with shape:
 else
 if data_format =’channels_first’
4D tensor with shape:
(samples, filters, output_row, output_col)
 if data_format=’channels_last’
4D tensor with shape:
(samples, output_row, output_col, filters)
where o_row and o_col depend on the shape of the filter and the padding
 if data_format =’channels_first’
4D tensor with shape:
Raises
 ValueError: in case of invalid constructor arguments.
References
 Convolutional LSTM Network: A Machine Learning Approach for Precipitation Nowcasting The current implementation does not include the feedback loop on the cells output

CLASS
¶ alias of
ConvLSTM2D

class
conx.layers.
ConvRecurrent2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ConvRecurrent2DLayer
Abstract base class for convolutional recurrent layers.
Do not use in a model – it’s not a functional layer!
Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of n integers, specifying the dimensions of the convolution window.
 strides: An integer or tuple/list of n integers,
specifying the strides of the convolution.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, time, ..., channels)
whilechannels_first
corresponds to inputs with shape(batch, time, channels, ...)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: An integer or tuple/list of n integers,
specifying
the dilation rate to use for dilated convolution.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying anystrides
value != 1.  return_sequences: Boolean. Whether to return the last output in the output sequence, or the full sequence.
 go_backwards: Boolean (default False). If True, rocess the input sequence backwards.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.
Input shape
5D tensor with shape
(num_samples, timesteps, channels, rows, cols)
.Output shape
 if
return_sequences
: 5D tensor with shape(num_samples, timesteps, channels, rows, cols)
.  else, 4D tensor with shape
(num_samples, channels, rows, cols)
.
Masking
This layer supports masking for input data with a variable numberof timesteps. To introduce masks to your data,use an Embedding layer with themask_zero
parameterset toTrue
. __**Note__:** for the time being, masking is only supported with Theano.
Note on using statefulness in RNNs
You can set RNN layers to be ‘stateful’, which means that the statescomputed for the samples in one batch will be reused as initial statesfor the samples in the next batch.This assumes a onetoone mapping betweensamples in different successive batches.To enable statefulness: specifystateful=True
in the layer constructor. specify a fixed batch size for your model, by passingabatch_input_size=(...)
to the first layer in your model.This is the expected shape of your inputs including the batch size.It should be a tuple of integers, e.g.(32, 10, 100)
.To reset the states of your model, call.reset_states()
on eithera specific layer, or on your entire model.
CLASS
¶ alias of
ConvRecurrent2D

class
conx.layers.
Convolution1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Convolution1DLayer
1D convolution layer (e.g. temporal convolution).
This layer creates a convolution kernel that is convolvedwith the layer input over a single spatial (or temporal) dimensionto produce a tensor of outputs.Ifuse_bias
is True, a bias vector is created and added to the outputs.Finally, ifactivation
is notNone
,it is applied to the outputs as well.When using this layer as the first layer in a model,provide aninput_shape
argument(tuple of integers orNone
, e.g.(10, 128)
for sequences of 10 vectors of 128dimensional vectors,or(None, 128)
for variablelength sequences of 128dimensional vectors.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of a single integer, specifying the length of the 1D convolution window.
 strides: An integer or tuple/list of a single integer,
specifying the stride length of the convolution.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: One of
"valid"
,"causal"
or"same"
(caseinsensitive)."valid"
means “no padding”."same"
results in padding the input such that the output has the same length as the original input."causal"
results in causal (dilated) convolutions, e.g. output[t] does not depend on input[t+1:]. Useful when modeling temporal data where the model should not violate the temporal order. See WaveNet: A Generative Model for Raw Audio, section 2.1.  dilation_rate: an integer or tuple/list of a single integer,
specifying
the dilation rate to use for dilated convolution.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying anystrides
value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
3D tensor with shape:
(batch_size, steps, input_dim)
Output shape
3D tensor with shape:(batch_size, new_steps, filters)
steps
value might have changed due to padding or strides.
CLASS
¶ alias of
Conv1D

class
conx.layers.
Convolution2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Convolution2DLayer
2D convolution layer (e.g. spatial convolution over images).
This layer creates a convolution kernel that is convolvedwith the layer input to produce a tensor ofoutputs. Ifuse_bias
is True,a bias vector is created and added to the outputs. Finally, ifactivation
is notNone
, it is applied to the outputs as well.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 3)
for 128x128 RGB picturesindata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 2 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(samples, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(samples, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(samples, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(samples, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.
CLASS
¶ alias of
Conv2D

class
conx.layers.
Convolution2DTransposeLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Convolution2DTransposeLayer
Transposed convolution layer (sometimes called Deconvolution).
The need for transposed convolutions generally arisesfrom the desire to use a transformation going in the opposite directionof a normal convolution, i.e., from something that has the shape of theoutput of some convolution to something that has the shape of its inputwhile maintaining a connectivity pattern that is compatible withsaid convolution.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 3)
for 128x128 RGB picturesindata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 2 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(batch, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(batch, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.References

CLASS
¶ alias of
Conv2DTranspose

class
conx.layers.
Convolution3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Convolution3DLayer
3D convolution layer (e.g. spatial convolution over volumes).
This layer creates a convolution kernel that is convolvedwith the layer input to produce a tensor ofoutputs. Ifuse_bias
is True,a bias vector is created and added to the outputs. Finally, ifactivation
is notNone
, it is applied to the outputs as well.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 128, 1)
for 128x128x128 volumeswith a single channel,indata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of 3 integers, specifying the depth, height and width of the 3D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 3 integers,
specifying the strides of the convolution along each spatial
dimension.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 3 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
5D tensor with shape:(samples, channels, conv_dim1, conv_dim2, conv_dim3)
if data_format=’channels_first’or 5D tensor with shape:(samples, conv_dim1, conv_dim2, conv_dim3, channels)
if data_format=’channels_last’.Output shape
5D tensor with shape:(samples, filters, new_conv_dim1, new_conv_dim2, new_conv_dim3)
if data_format=’channels_first’or 5D tensor with shape:(samples, new_conv_dim1, new_conv_dim2, new_conv_dim3, filters)
if data_format=’channels_last’.new_conv_dim1
,new_conv_dim2
andnew_conv_dim3
values might have changed due to padding.
CLASS
¶ alias of
Conv3D

class
conx.layers.
Cropping1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Cropping1DLayer
Cropping layer for 1D input (e.g. temporal sequence).
It crops along the time dimension (axis 1).
Arguments
 cropping: int or tuple of int (length 2) How many units should be trimmed off at the beginning and end of the cropping dimension (axis 1). If a single int is provided, the same value will be used for both.
Input shape
3D tensor with shape
(batch, axis_to_crop, features)
Output shape
3D tensor with shape
(batch, cropped_axis, features)

CLASS
¶ alias of
Cropping1D

class
conx.layers.
Cropping2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Cropping2DLayer
Cropping layer for 2D input (e.g. picture).
It crops along spatial dimensions, i.e. width and height.
Arguments
 cropping: int, or tuple of 2 ints, or tuple of 2 tuples of 2
ints.
 If int: the same symmetric cropping is applied to width and height.
 If tuple of 2 ints:
interpreted as two different
symmetric cropping values for height and width:
(symmetric_height_crop, symmetric_width_crop)
.  If tuple of 2 tuples of 2 ints:
interpreted as
((top_crop, bottom_crop), (left_crop, right_crop))
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
4D tensor with shape:
 If
data_format
is"channels_last"
:(batch, rows, cols, channels)
 If
data_format
is"channels_first"
:(batch, channels, rows, cols)
Output shape
4D tensor with shape:
 If
data_format
is"channels_last"
:(batch, cropped_rows, cropped_cols, channels)
 If
data_format
is"channels_first"
:(batch, channels, cropped_rows, cropped_cols)
Examples
# Crop the input 2D images or feature maps model = Sequential() model.add(Cropping2D(cropping=((2, 2), (4, 4)), input_shape=(28, 28, 3))) # now model.output_shape == (None, 24, 20, 3) model.add(Conv2D(64, (3, 3), padding='same')) model.add(Cropping2D(cropping=((2, 2), (2, 2)))) # now model.output_shape == (None, 20, 16. 64)

CLASS
¶ alias of
Cropping2D
 cropping: int, or tuple of 2 ints, or tuple of 2 tuples of 2
ints.

class
conx.layers.
Cropping3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Cropping3DLayer
Cropping layer for 3D data (e.g. spatial or spatiotemporal).
Arguments
 cropping: int, or tuple of 3 ints, or tuple of 3 tuples of 2
ints.
 If int: the same symmetric cropping is applied to depth, height, and width.
 If tuple of 3 ints:
interpreted as two different
symmetric cropping values for depth, height, and width:
(symmetric_dim1_crop, symmetric_dim2_crop, symmetric_dim3_crop)
.  If tuple of 3 tuples of 2 ints:
interpreted as
((left_dim1_crop, right_dim1_crop), (left_dim2_crop, right_dim2_crop), (left_dim3_crop, right_dim3_crop))
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
5D tensor with shape:
 If
data_format
is"channels_last"
:(batch, first_axis_to_crop, second_axis_to_crop, third_axis_to_crop, depth)
 If
data_format
is"channels_first"
:(batch, depth, first_axis_to_crop, second_axis_to_crop, third_axis_to_crop)
Output shape
5D tensor with shape:
 If
data_format
is"channels_last"
:(batch, first_cropped_axis, second_cropped_axis, third_cropped_axis, depth)
 If
data_format
is"channels_first"
:(batch, depth, first_cropped_axis, second_cropped_axis, third_cropped_axis)

CLASS
¶ alias of
Cropping3D
 cropping: int, or tuple of 3 ints, or tuple of 3 tuples of 2
ints.

class
conx.layers.
CuDNNGRULayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
CuDNNGRULayer
Fast GRU implementation backed by CuDNN.
Can only be run on GPU, with the TensorFlow backend.
Arguments
 units: Positive integer, dimensionality of the output space.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 return_sequences: Boolean. Whether to return the last output. in the output sequence, or the full sequence.
 return_state: Boolean. Whether to return the last state in addition to the output.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.

CLASS
¶ alias of
CuDNNGRU

class
conx.layers.
CuDNNLSTMLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
CuDNNLSTMLayer
Fast LSTM implementation backed by CuDNN.
Can only be run on GPU, with the TensorFlow backend.
Arguments
 units: Positive integer, dimensionality of the output space.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  unit_forget_bias: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force
bias_initializer="zeros"
. This is recommended in Jozefowicz et al.  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 return_sequences: Boolean. Whether to return the last output. in the output sequence, or the full sequence.
 return_state: Boolean. Whether to return the last state in addition to the output.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.

CLASS
¶ alias of
CuDNNLSTM

class
conx.layers.
Deconv2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Deconv2DLayer
Transposed convolution layer (sometimes called Deconvolution).
The need for transposed convolutions generally arisesfrom the desire to use a transformation going in the opposite directionof a normal convolution, i.e., from something that has the shape of theoutput of some convolution to something that has the shape of its inputwhile maintaining a connectivity pattern that is compatible withsaid convolution.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 3)
for 128x128 RGB picturesindata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 2 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(batch, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(batch, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.References

CLASS
¶ alias of
Conv2DTranspose

class
conx.layers.
Deconv3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Deconv3DLayer
Transposed convolution layer (sometimes called Deconvolution).
The need for transposed convolutions generally arisesfrom the desire to use a transformation going in the opposite directionof a normal convolution, i.e., from something that has the shape of theoutput of some convolution to something that has the shape of its inputwhile maintaining a connectivity pattern that is compatible withsaid convolution.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 128, 3)
for a 128x128x128 volume with 3 channelsifdata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).
 kernel_size: An integer or tuple/list of 3 integers, specifying the width and height of the 3D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 3 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, depth, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, depth, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 3 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
5D tensor with shape:(batch, channels, depth, rows, cols)
if data_format=’channels_first’or 5D tensor with shape:(batch, depth, rows, cols, channels)
if data_format=’channels_last’.Output shape
5D tensor with shape:(batch, filters, new_depth, new_rows, new_cols)
if data_format=’channels_first’or 5D tensor with shape:(batch, new_depth, new_rows, new_cols, filters)
if data_format=’channels_last’.depth
androws
andcols
values might have changed due to padding.References

CLASS
¶ alias of
Conv3DTranspose

class
conx.layers.
Deconvolution2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Deconvolution2DLayer
Transposed convolution layer (sometimes called Deconvolution).
The need for transposed convolutions generally arisesfrom the desire to use a transformation going in the opposite directionof a normal convolution, i.e., from something that has the shape of theoutput of some convolution to something that has the shape of its inputwhile maintaining a connectivity pattern that is compatible withsaid convolution.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 3)
for 128x128 RGB picturesindata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 2 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(batch, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(batch, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.References

CLASS
¶ alias of
Conv2DTranspose

class
conx.layers.
Deconvolution3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
Deconvolution3DLayer
Transposed convolution layer (sometimes called Deconvolution).
The need for transposed convolutions generally arisesfrom the desire to use a transformation going in the opposite directionof a normal convolution, i.e., from something that has the shape of theoutput of some convolution to something that has the shape of its inputwhile maintaining a connectivity pattern that is compatible withsaid convolution.When using this layer as the first layer in a model,provide the keyword argumentinput_shape
(tuple of integers, does not include the sample axis),e.g.input_shape=(128, 128, 128, 3)
for a 128x128x128 volume with 3 channelsifdata_format="channels_last"
.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number of output filters in the convolution).
 kernel_size: An integer or tuple/list of 3 integers, specifying the width and height of the 3D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 3 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, depth, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, depth, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  dilation_rate: an integer or tuple/list of 3 integers,
specifying
the dilation rate to use for dilated convolution.
Can be a single integer to specify the same value for
all spatial dimensions.
Currently, specifying any
dilation_rate
value != 1 is incompatible with specifying any stride value != 1.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
5D tensor with shape:(batch, channels, depth, rows, cols)
if data_format=’channels_first’or 5D tensor with shape:(batch, depth, rows, cols, channels)
if data_format=’channels_last’.Output shape
5D tensor with shape:(batch, filters, new_depth, new_rows, new_cols)
if data_format=’channels_first’or 5D tensor with shape:(batch, new_depth, new_rows, new_cols, filters)
if data_format=’channels_last’.depth
androws
andcols
values might have changed due to padding.References

CLASS
¶ alias of
Conv3DTranspose

class
conx.layers.
DotLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
DotLayer
Layer that computes a dot product between samples in two tensors.
E.g. if applied to two tensorsa
andb
of shape(batch_size, n)
,the output will be a tensor of shape(batch_size, 1)
where each entryi
will be the dot product betweena[i]
andb[i]
.Arguments
 axes: Integer or tuple of integers, axis or axes along which to take the dot product.
 normalize: Whether to L2normalize samples along the dot product axis before taking the dot product. If set to True, then the output of the dot product is the cosine proximity between the two samples.
 __**kwargs__: Standard layer keyword arguments.

CLASS
¶ alias of
Dot

class
conx.layers.
DropoutLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
DropoutLayer
Applies Dropout to the input.
Dropout consists in randomly settinga fractionrate
of input units to 0 at each update during training time,which helps prevent overfitting.Arguments
 rate: float between 0 and 1. Fraction of the input units to drop.
 noise_shape: 1D integer tensor representing the shape of the
binary dropout mask that will be multiplied with the input.
For instance, if your inputs have shape
(batch_size, timesteps, features)
and you want the dropout mask to be the same for all timesteps, you can usenoise_shape=(batch_size, 1, features)
.  seed: A Python integer to use as random seed.
References

CLASS
¶ alias of
Dropout

class
conx.layers.
ELULayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ELULayer
Exponential Linear Unit.
It follows:f(x) = alpha * (exp(x)  1.) for x < 0
,f(x) = x for x >= 0
.Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as the input.
Arguments
 alpha: scale for the negative factor.
References

CLASS
¶ alias of
ELU

class
conx.layers.
EmbeddingLayer
(name, in_size, out_size, **params)[source]¶ Bases:
conx.layers.Layer
A class for embeddings. WIP.

class
conx.layers.
FlattenLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
FlattenLayer
Flattens the input. Does not affect the batch size.
Example
model = Sequential() model.add(Conv2D(64, 3, 3, border_mode='same', input_shape=(3, 32, 32))) # now: model.output_shape == (None, 64, 32, 32) model.add(Flatten()) # now: model.output_shape == (None, 65536)

CLASS
¶ alias of
Flatten


class
conx.layers.
GRUCellLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GRUCellLayer
Cell class for the GRU layer.
Arguments
 units: Positive integer, dimensionality of the output space.
 activation: Activation function to use
(see activations).
If you pass None, no activation is applied
(ie. “linear” activation:
a(x) = x
).  recurrent_activation: Activation function to use for the recurrent step (see activations).
 use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
 recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.
 implementation: Implementation mode, either 1 or 2. Mode 1 will structure its operations as a larger number of smaller dot products and additions, whereas mode 2 will batch them into fewer, larger operations. These modes will have different performance profiles on different hardware and for different applications.

CLASS
¶ alias of
GRUCell

class
conx.layers.
GRULayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GRULayer
Gated Recurrent Unit  Cho et al. 2014.
Arguments
 units: Positive integer, dimensionality of the output space.
 activation: Activation function to use
(see activations).
If you pass None, no activation is applied
(ie. “linear” activation:
a(x) = x
).  recurrent_activation: Activation function to use for the recurrent step (see activations).
 use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
 recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.
 implementation: Implementation mode, either 1 or 2. Mode 1 will structure its operations as a larger number of smaller dot products and additions, whereas mode 2 will batch them into fewer, larger operations. These modes will have different performance profiles on different hardware and for different applications.
 return_sequences: Boolean. Whether to return the last output. in the output sequence, or the full sequence.
 return_state: Boolean. Whether to return the last state in addition to the output.
 go_backwards: Boolean (default False). If True, process the input sequence backwards and return the reversed sequence.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.
 unroll: Boolean (default False). If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speedup a RNN, although it tends to be more memoryintensive. Unrolling is only suitable for short sequences.
References
 On the Properties of Neural Machine Translation: EncoderDecoder Approaches
 Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling
 A Theoretically Grounded Application of Dropout in Recurrent Neural Networks

CLASS
¶ alias of
GRU

class
conx.layers.
GaussianDropoutLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GaussianDropoutLayer
Apply multiplicative 1centered Gaussian noise.
As it is a regularization layer, it is only active at training time.
Arguments
 rate: float, drop probability (as with
Dropout
). The multiplicative noise will have standard deviationsqrt(rate / (1  rate))
.
Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as input.
References

CLASS
¶ alias of
GaussianDropout
 rate: float, drop probability (as with

class
conx.layers.
GaussianNoiseLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GaussianNoiseLayer
Apply additive zerocentered Gaussian noise.
This is useful to mitigate overfitting(you could see it as a form of random data augmentation).Gaussian Noise (GS) is a natural choice as corruption processfor real valued inputs.As it is a regularization layer, it is only active at training time.
Arguments
 stddev: float, standard deviation of the noise distribution.
Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as input.

CLASS
¶ alias of
GaussianNoise

class
conx.layers.
GlobalAveragePooling1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalAveragePooling1DLayer
Global average pooling operation for temporal data.
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
2D tensor with shape:(batch_size, features)

CLASS
¶ alias of
GlobalAveragePooling1D


class
conx.layers.
GlobalAveragePooling2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalAveragePooling2DLayer
Global average pooling operation for spatial data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalAveragePooling2D
 data_format: A string,
one of

class
conx.layers.
GlobalAveragePooling3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalAveragePooling3DLayer
Global Average pooling operation for 3D data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalAveragePooling3D
 data_format: A string,
one of

class
conx.layers.
GlobalAvgPool1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalAvgPool1DLayer
Global average pooling operation for temporal data.
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
2D tensor with shape:(batch_size, features)

CLASS
¶ alias of
GlobalAveragePooling1D


class
conx.layers.
GlobalAvgPool2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalAvgPool2DLayer
Global average pooling operation for spatial data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalAveragePooling2D
 data_format: A string,
one of

class
conx.layers.
GlobalAvgPool3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalAvgPool3DLayer
Global Average pooling operation for 3D data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalAveragePooling3D
 data_format: A string,
one of

class
conx.layers.
GlobalMaxPool1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalMaxPool1DLayer
Global max pooling operation for temporal data.
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
2D tensor with shape:(batch_size, features)

CLASS
¶ alias of
GlobalMaxPooling1D


class
conx.layers.
GlobalMaxPool2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalMaxPool2DLayer
Global max pooling operation for spatial data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalMaxPooling2D
 data_format: A string,
one of

class
conx.layers.
GlobalMaxPool3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalMaxPool3DLayer
Global Max pooling operation for 3D data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalMaxPooling3D
 data_format: A string,
one of

class
conx.layers.
GlobalMaxPooling1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalMaxPooling1DLayer
Global max pooling operation for temporal data.
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
2D tensor with shape:(batch_size, features)

CLASS
¶ alias of
GlobalMaxPooling1D


class
conx.layers.
GlobalMaxPooling2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalMaxPooling2DLayer
Global max pooling operation for spatial data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalMaxPooling2D
 data_format: A string,
one of

class
conx.layers.
GlobalMaxPooling3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
GlobalMaxPooling3DLayer
Global Max pooling operation for 3D data.
Arguments
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
2D tensor with shape:(batch_size, channels)

CLASS
¶ alias of
GlobalMaxPooling3D
 data_format: A string,
one of

class
conx.layers.
HighwayLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
HighwayLayer
Densely connected highway network.Highway layers are a natural extension of LSTMs to feedforward networks.Arguments init: name of initialization function for the weights of the
layer
(see initializations),
or alternatively, Theano function to use for weights
initialization. This parameter is only relevant
if you don’t pass a
weights
argument.  activation: name of activation function to use (see activations), or alternatively, elementwise Theano function. If you don’t specify anything, no activation is applied (ie. “linear” activation: a(x) = x).
 weights: list of Numpy arrays to set as initial weights.
The list should have 2 elements, of shape
(input_dim, output_dim)
and (output_dim,) for weights and biases respectively.  W_regularizer: instance of WeightRegularizer (eg. L1 or L2 regularization), applied to the main weights matrix.
 b_regularizer: instance of WeightRegularizer, applied to the bias.
 activity_regularizer: instance of ActivityRegularizer, applied to the network output.
 W_constraint: instance of the constraints module (eg. maxnorm, nonneg), applied to the main weights matrix.
 b_constraint: instance of the constraints module, applied to the bias.
 bias: whether to include a bias (i.e. make the layer affine rather than linear).
 input_dim: dimensionality of the input (integer). This argument
(or alternatively, the keyword argument
input_shape
) is required when using this layer as the first layer in a model. Input shape
2D tensor with shape:(nb_samples, input_dim)
.Output shape2D tensor with shape:(nb_samples, input_dim)
.References
CLASS
¶ alias of
Highway
 init: name of initialization function for the weights of the
layer
(see initializations),
or alternatively, Theano function to use for weights
initialization. This parameter is only relevant
if you don’t pass a

class
conx.layers.
ImageLayer
(name, dimensions, depth, **params)[source]¶ Bases:
conx.layers.Layer
A class for images. WIP.

class
conx.layers.
InputLayerLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
InputLayerLayer
Layer to be used as an entry point into a graph.
It can either wrap an existing tensor (pass aninput_tensor
argument)or create its a placeholder tensor (pass argumentsinput_shape
orbatch_input_shape
as well asdtype
).Arguments
 input_shape: Shape tuple, not including the batch axis.
 batch_size: Optional input batch size (integer or None).
 batch_input_shape: Shape tuple, including the batch axis.
 dtype: Datatype of the input.
 input_tensor: Optional tensor to use as layer input instead of creating a placeholder.
 sparse: Boolean, whether the placeholder created is meant to be sparse.
 name: Name of the layer (string).

CLASS
¶ alias of
InputLayer

class
conx.layers.
LSTMCellLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
LSTMCellLayer
Cell class for the LSTM layer.
Arguments
 units: Positive integer, dimensionality of the output space.
 activation: Activation function to use
(see activations).
If you pass None, no activation is applied
(ie. “linear” activation:
a(x) = x
).  recurrent_activation: Activation function to use for the recurrent step (see activations).
 use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 unit_forget_bias: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force
bias_initializer="zeros"
. This is recommended in Jozefowicz et al.  kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
 recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.
 implementation: Implementation mode, either 1 or 2. Mode 1 will structure its operations as a larger number of smaller dot products and additions, whereas mode 2 will batch them into fewer, larger operations. These modes will have different performance profiles on different hardware and for different applications.

CLASS
¶ alias of
LSTMCell

class
conx.layers.
LSTMLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
LSTMLayer
LongShort Term Memory layer  Hochreiter 1997.
Arguments
 units: Positive integer, dimensionality of the output space.
 activation: Activation function to use
(see activations).
If you pass None, no activation is applied
(ie. “linear” activation:
a(x) = x
).  recurrent_activation: Activation function to use for the recurrent step (see activations).
 use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 unit_forget_bias: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force
bias_initializer="zeros"
. This is recommended in Jozefowicz et al.  kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
 recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.
 implementation: Implementation mode, either 1 or 2. Mode 1 will structure its operations as a larger number of smaller dot products and additions, whereas mode 2 will batch them into fewer, larger operations. These modes will have different performance profiles on different hardware and for different applications.
 return_sequences: Boolean. Whether to return the last output. in the output sequence, or the full sequence.
 return_state: Boolean. Whether to return the last state in addition to the output.
 go_backwards: Boolean (default False). If True, process the input sequence backwards and return the reversed sequence.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.
 unroll: Boolean (default False). If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speedup a RNN, although it tends to be more memoryintensive. Unrolling is only suitable for short sequences.
References
 Long shortterm memory (original 1997 paper)
 Learning to forget: Continual prediction with LSTM
 Supervised sequence labeling with recurrent neural networks
 A Theoretically Grounded Application of Dropout in Recurrent Neural Networks

CLASS
¶ alias of
LSTM

class
conx.layers.
LambdaLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
LambdaLayer
Wraps arbitrary expression as a
Layer
object.Examples
# add a x > x^2 layer model.add(Lambda(lambda x: x ** 2))
# add a layer that returns the concatenation # of the positive part of the input and # the opposite of the negative part def antirectifier(x): x = K.mean(x, axis=1, keepdims=True) x = K.l2_normalize(x, axis=1) pos = K.relu(x) neg = K.relu(x) return K.concatenate([pos, neg], axis=1) def antirectifier_output_shape(input_shape): shape = list(input_shape) assert len(shape) == 2 # only valid for 2D tensors shape[1] *= 2 return tuple(shape) model.add(Lambda(antirectifier, output_shape=antirectifier_output_shape))
Arguments
 function: The function to be evaluated. Takes input tensor as first argument.
 output_shape: Expected output shape from function.
Only relevant when using Theano.
Can be a tuple or function.
If a tuple, it only specifies the first dimension onward;
sample dimension is assumed either the same as the input:
output_shape = (input_shape[0], ) + output_shape
or, the input isNone
and the sample dimension is alsoNone
:output_shape = (None, ) + output_shape
If a function, it specifies the entire shape as a function of the input shape:output_shape = f(input_shape)
 arguments: optional dictionary of keyword arguments to be passed to the function.
Input shape
Arbitrary. Use the keyword argument input_shape(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Specified byoutput_shape
argument(or autoinferred when using TensorFlow).
CLASS
¶ alias of
Lambda

class
conx.layers.
Layer
(name: str, shape, **params)[source]¶ Bases:
conx.layers._BaseLayer
The default layer type. Will create either an InputLayer, or DenseLayer, depending on its context after
Network.connect
.Parameters: name – The name of the layer. Must be unique in this network. Should not contain special HTML characters. Examples
>>> layer = Layer("input", 10) >>> layer.name 'input'
>>> from conx import Network >>> net = Network("XOR2") >>> net.add(Layer("input", 2)) >>> net.add(Layer("hidden", 5)) >>> net.add(Layer("output", 2)) >>> net.connect() >>> net["input"].kind() 'input' >>> net["output"].kind() 'output'
Note
See also:
Network
,Network.add
, andNetwork.connect
for more information. See https://keras.io/ for more information on Keras layers.
CLASS
¶ alias of
Dense


class
conx.layers.
LayerLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
LayerLayer
Abstract base layer class.
Properties
 name: String, must be unique within a model.
 input_spec: List of InputSpec class instances
each entry describes one required input:
 ndim
 dtype
A layer with
n
input tensors must have aninput_spec
of lengthn
.
 trainable: Boolean, whether the layer weights will be updated during training.
 uses_learning_phase: Whether any operation
of the layer uses
K.in_training_phase()
orK.in_test_phase()
.  input_shape: Shape tuple. Provided for convenience,
but note that there may be cases in which this
attribute is illdefined (e.g. a shared layer
with multiple input shapes), in which case
requesting
input_shape
will raise an Exception. Prefer usinglayer.get_input_shape_for(input_shape)
, orlayer.get_input_shape_at(node_index)
.  output_shape: Shape tuple. See above.
 inbound_nodes: List of nodes.
 outbound_nodes: List of nodes.
input, output: Input/output tensor(s). Note that if the layer is used
more than once (shared layer), this is illdefined
and will raise an exception. In such cases, use
layer.get_input_at(node_index)
. input_mask, output_mask: Same as above, for masks.  trainable_weights: List of variables.
 non_trainable_weights: List of variables.
 weights: The concatenation of the lists trainable_weights and non_trainable_weights (in this order).
Methods
call(x, mask=None): Where the layer’s logic lives.call(x, mask=None): Wrapper around the layer logic (call
).If x is a Keras tensor: Connect current layer with last layer from tensor:self._add_inbound_node(last_layer)
 Add layer to tensor historyIf layer is not built: Build from x._keras_shapeget_weights()set_weights(weights)get_config()count_params()compute_output_shape(input_shape)compute_mask(x, mask)get_input_at(node_index)get_output_at(node_index)get_input_shape_at(node_index)get_output_shape_at(node_index)get_input_mask_at(node_index)get_output_mask_at(node_index)Class Methods
from_config(config)
Internal methods:
build(input_shape)_add_inbound_node(layer, index=0)assert_input_compatibility()

class
conx.layers.
LeakyReLULayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
LeakyReLULayer
Leaky version of a Rectified Linear Unit.
It allows a small gradient when the unit is not active:f(x) = alpha * x for x < 0
,f(x) = x for x >= 0
.Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as the input.
Arguments
 alpha: float >= 0. Negative slope coefficient.
References

CLASS
¶ alias of
LeakyReLU

class
conx.layers.
LocallyConnected1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
LocallyConnected1DLayer
Locallyconnected layer for 1D inputs.
TheLocallyConnected1D
layer works similarly totheConv1D
layer, except that weights are unshared,that is, a different set of filters is applied at each different patchof the input.Example
# apply a unshared weight convolution 1d of length 3 to a sequence with # 10 timesteps, with 64 output filters model = Sequential() model.add(LocallyConnected1D(64, 3, input_shape=(10, 32))) # now model.output_shape == (None, 8, 64) # add a new conv1d on top model.add(LocallyConnected1D(32, 3)) # now model.output_shape == (None, 6, 32)
Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of a single integer, specifying the length of the 1D convolution window.
 strides: An integer or tuple/list of a single integer,
specifying the stride length of the convolution.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: Currently only supports
"valid"
(caseinsensitive)."same"
may be supported in the future.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
3D tensor with shape:
(batch_size, steps, input_dim)
Output shape
3D tensor with shape:(batch_size, new_steps, filters)
steps
value might have changed due to padding or strides.
CLASS
¶ alias of
LocallyConnected1D

class
conx.layers.
LocallyConnected2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
LocallyConnected2DLayer
Locallyconnected layer for 2D inputs.
TheLocallyConnected2D
layer works similarlyto theConv2D
layer, except that weights are unshared,that is, a different set of filters is applied at eachdifferent patch of the input.Examples
# apply a 3x3 unshared weights convolution with 64 output filters on a 32x32 image # with `data_format="channels_last"`: model = Sequential() model.add(LocallyConnected2D(64, (3, 3), input_shape=(32, 32, 3))) # now model.output_shape == (None, 30, 30, 64) # notice that this layer will consume (30*30)*(3*3*3*64) + (30*30)*64 parameters # add a 3x3 unshared weights convolution on top, with 32 output filters: model.add(LocallyConnected2D(32, (3, 3))) # now model.output_shape == (None, 28, 28, 32)
Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers, specifying the strides of the convolution along the width and height. Can be a single integer to specify the same value for all spatial dimensions.
 padding: Currently only support
"valid"
(caseinsensitive)."same"
will be supported in future.  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to the kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(samples, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(samples, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(samples, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(samples, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.
CLASS
¶ alias of
LocallyConnected2D

class
conx.layers.
MaskingLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaskingLayer
Masks a sequence by using a mask value to skip timesteps.
For each timestep in the input tensor (dimension #1 in the tensor),if all values in the input tensor at that timestepare equal tomask_value
, then the timestep will be masked (skipped)in all downstream layers (as long as they support masking).If any downstream layer does not support masking yet receives suchan input mask, an exception will be raised.Example
Consider a Numpy data arrayx
of shape(samples, timesteps, features)
,to be fed to an LSTM layer.You want to mask timestep #3 and #5 because you lack data forthese timesteps. You can: set
x[:, 3, :] = 0.
andx[:, 5, :] = 0.
 insert a
Masking
layer withmask_value=0.
before the LSTM layer:
model = Sequential() model.add(Masking(mask_value=0., input_shape=(timesteps, features))) model.add(LSTM(32))

CLASS
¶ alias of
Masking
 set

class
conx.layers.
MaxPool1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaxPool1DLayer
Max pooling operation for temporal data.
Arguments
 pool_size: Integer, size of the max pooling windows.
 strides: Integer, or None. Factor by which to downscale.
E.g. 2 will halve the input.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
3D tensor with shape:
(batch_size, downsampled_steps, features)
.
CLASS
¶ alias of
MaxPooling1D

class
conx.layers.
MaxPool2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaxPool2DLayer
Max pooling operation for spatial data.
Arguments
 pool_size: integer or tuple of 2 integers, factors by which to downscale (vertical, horizontal). (2, 2) will halve the input in both spatial dimension. If only one integer is specified, the same window length will be used for both dimensions.
 strides: Integer, tuple of 2 integers, or None.
Strides values.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, pooled_rows, pooled_cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, pooled_rows, pooled_cols)

CLASS
¶ alias of
MaxPooling2D

class
conx.layers.
MaxPool3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaxPool3DLayer
Max pooling operation for 3D data (spatial or spatiotemporal).
Arguments
 pool_size: tuple of 3 integers, factors by which to downscale (dim1, dim2, dim3). (2, 2, 2) will halve the size of the 3D input in each dimension.
 strides: tuple of 3 integers, or None. Strides values.
 padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)

CLASS
¶ alias of
MaxPooling3D

class
conx.layers.
MaxPooling1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaxPooling1DLayer
Max pooling operation for temporal data.
Arguments
 pool_size: Integer, size of the max pooling windows.
 strides: Integer, or None. Factor by which to downscale.
E.g. 2 will halve the input.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).
Input shape
3D tensor with shape:
(batch_size, steps, features)
.Output shape
3D tensor with shape:
(batch_size, downsampled_steps, features)
.
CLASS
¶ alias of
MaxPooling1D

class
conx.layers.
MaxPooling2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaxPooling2DLayer
Max pooling operation for spatial data.
Arguments
 pool_size: integer or tuple of 2 integers, factors by which to downscale (vertical, horizontal). (2, 2) will halve the input in both spatial dimension. If only one integer is specified, the same window length will be used for both dimensions.
 strides: Integer, tuple of 2 integers, or None.
Strides values.
If None, it will default to
pool_size
.  padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, rows, cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, rows, cols)
Output shape
 If
data_format='channels_last'
: 4D tensor with shape:(batch_size, pooled_rows, pooled_cols, channels)
 If
data_format='channels_first'
: 4D tensor with shape:(batch_size, channels, pooled_rows, pooled_cols)

CLASS
¶ alias of
MaxPooling2D

class
conx.layers.
MaxPooling3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaxPooling3DLayer
Max pooling operation for 3D data (spatial or spatiotemporal).
Arguments
 pool_size: tuple of 3 integers, factors by which to downscale (dim1, dim2, dim3). (2, 2, 2) will halve the size of the 3D input in each dimension.
 strides: tuple of 3 integers, or None. Strides values.
 padding: One of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)
Output shape
 If
data_format='channels_last'
: 5D tensor with shape:(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)
 If
data_format='channels_first'
: 5D tensor with shape:(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)

CLASS
¶ alias of
MaxPooling3D

class
conx.layers.
MaximumLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaximumLayer
Layer that computes the maximum (elementwise) a list of inputs.
It takes as input a list of tensors,all of the same shape, and returnsa single tensor (also of the same shape).
CLASS
¶ alias of
Maximum


class
conx.layers.
MaxoutDenseLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MaxoutDenseLayer
A dense maxout layer.AMaxoutDense
layer takes the elementwise maximum ofnb_feature
Dense(input_dim, output_dim)
linear layers.This allows the layer to learn a convex,piecewise linear activation function over the inputs.Note that this is a linear layer;if you wish to apply activation function(you shouldn’t need to –they are universal function approximators),anActivation
layer must be added after.Arguments output_dim: int > 0.
 nb_feature: number of Dense layers to use internally.
 init: name of initialization function for the weights of the
layer
(see initializations),
or alternatively, Theano function to use for weights
initialization. This parameter is only relevant
if you don’t pass a
weights
argument.  weights: list of Numpy arrays to set as initial weights.
The list should have 2 elements, of shape
(input_dim, output_dim)
and (output_dim,) for weights and biases respectively.  W_regularizer: instance of WeightRegularizer (eg. L1 or L2 regularization), applied to the main weights matrix.
 b_regularizer: instance of WeightRegularizer, applied to the bias.
 activity_regularizer: instance of ActivityRegularizer, applied to the network output.
 W_constraint: instance of the constraints module (eg. maxnorm, nonneg), applied to the main weights matrix.
 b_constraint: instance of the constraints module, applied to the bias.
 bias: whether to include a bias (i.e. make the layer affine rather than linear).
 input_dim: dimensionality of the input (integer). This argument
(or alternatively, the keyword argument
input_shape
) is required when using this layer as the first layer in a model. Input shape
2D tensor with shape:(nb_samples, input_dim)
.Output shape2D tensor with shape:(nb_samples, output_dim)
.References
CLASS
¶ alias of
MaxoutDense

class
conx.layers.
MergeLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MergeLayer
AMerge
layer can be used to merge a list of tensorsinto a single tensor, following some mergemode
.Examplemodel1 = Sequential() model1.add(Dense(32, input_dim=32)) model2 = Sequential() model2.add(Dense(32, input_dim=32)) merged_model = Sequential() merged_model.add(Merge([model1, model2], mode='concat', concat_axis=1))
Arguments
 layers: Can be a list of Keras tensors or a list of layer instances. Must be more than one layer/tensor.
 mode: String or lambda/function. If string, must be one
 of: ‘sum’, ‘mul’, ‘concat’, ‘ave’, ‘cos’, ‘dot’, ‘max’. If lambda/function, it should take as input a list of tensors and return a single tensor.
 concat_axis: Integer, axis to use in mode
concat
.  dot_axes: Integer or tuple of integers,
axes to use in mode
dot
orcos
.  output_shape: Either a shape tuple (tuple of integers),
or a lambda/function
to compute
output_shape
(only if merge mode is a lambda/function). If the argument is a tuple, it should be expected output shape, not including the batch size (same convention as theinput_shape
argument in layers). If the argument is callable, it should take as input a list of shape tuples (1:1 mapping to input tensors) and return a single shape tuple, including the batch size (same convention as thecompute_output_shape
method of layers).  node_indices: Optional list of integers containing the output node index for each input layer (in case some input layers have multiple output nodes). will default to an array of 0s if not provided.
 tensor_indices: Optional list of indices of output tensors to consider for merging (in case some input layer node returns multiple tensors).
 output_mask: Mask or lambda/function to compute the output mask (only if merge mode is a lambda/function). If the latter case, it should take as input a list of masks and return a single mask.

CLASS
¶ alias of
Merge

class
conx.layers.
MinimumLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MinimumLayer
Layer that computes the minimum (elementwise) a list of inputs.
It takes as input a list of tensors,all of the same shape, and returnsa single tensor (also of the same shape).
CLASS
¶ alias of
Minimum


class
conx.layers.
MultiplyLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
MultiplyLayer
Layer that multiplies (elementwise) a list of inputs.
It takes as input a list of tensors,all of the same shape, and returnsa single tensor (also of the same shape).
CLASS
¶ alias of
Multiply


class
conx.layers.
PReLULayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
PReLULayer
Parametric Rectified Linear Unit.
It follows:f(x) = alpha * x for x < 0
,f(x) = x for x >= 0
,wherealpha
is a learned array with the same shape as x.Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as the input.
Arguments
 alpha_initializer: initializer function for the weights.
 alpha_regularizer: regularizer for the weights.
 alpha_constraint: constraint for the weights.
 shared_axes: the axes along which to share learnable
parameters for the activation function.
For example, if the incoming feature maps
are from a 2D convolution
with output shape
(batch, height, width, channels)
, and you wish to share parameters across space so that each filter only has one set of parameters, setshared_axes=[1, 2]
.
References

CLASS
¶ alias of
PReLU

class
conx.layers.
PermuteLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
PermuteLayer
Permutes the dimensions of the input according to a given pattern.
Useful for e.g. connecting RNNs and convnets together.
Example
model = Sequential() model.add(Permute((2, 1), input_shape=(10, 64))) # now: model.output_shape == (None, 64, 10) # note: `None` is the batch dimension
Arguments
 dims: Tuple of integers. Permutation pattern, does not include
the
samples dimension. Indexing starts at 1.
For instance,
(2, 1)
permutes the first and second dimension of the input.
Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same as the input shape, but with the dimensions reordered accordingto the specified pattern.
CLASS
¶ alias of
Permute
 dims: Tuple of integers. Permutation pattern, does not include
the
samples dimension. Indexing starts at 1.
For instance,

class
conx.layers.
RNNLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
RNNLayer
Base class for recurrent layers.
Arguments
 cell: A RNN cell instance. A RNN cell is a class that has:
 a
call(input_at_t, states_at_t)
method, returning(output_at_t, states_at_t_plus_1)
. The call method of the cell can also take the optional argumentconstants
, see section “Note on passing external constants” below.  a
state_size
attribute. This can be a single integer (single state) in which case it is the size of the recurrent state (which should be the same as the size of the cell output). This can also be a list/tuple of integers (one size per state). In this case, the first entry (state_size[0]
) should be the same as the size of the cell output. It is also possible forcell
to be a list of RNN cell instances, in which cases the cells get stacked on after the other in the RNN, implementing an efficient stacked RNN.
 a
 return_sequences: Boolean. Whether to return the last output. in the output sequence, or the full sequence.
 return_state: Boolean. Whether to return the last state in addition to the output.
 go_backwards: Boolean (default False). If True, process the input sequence backwards and return the reversed sequence.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.
 unroll: Boolean (default False). If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speedup a RNN, although it tends to be more memoryintensive. Unrolling is only suitable for short sequences.
 input_dim: dimensionality of the input (integer).
This argument (or alternatively,
the keyword argument
input_shape
) is required when using this layer as the first layer in a model.  input_length: Length of input sequences, to be specified
when it is constant.
This argument is required if you are going to connect
Flatten
thenDense
layers upstream (without it, the shape of the dense outputs cannot be computed). Note that if the recurrent layer is not the first layer in your model, you would need to specify the input length at the level of the first layer (e.g. via theinput_shape
argument)
Input shape
3D tensor with shape
(batch_size, timesteps, input_dim)
.Output shape
 if
return_state
: a list of tensors. The first tensor is the output. The remaining tensors are the last states, each with shape(batch_size, units)
.  if
return_sequences
: 3D tensor with shape(batch_size, timesteps, units)
.  else, 2D tensor with shape
(batch_size, units)
.
Masking
This layer supports masking for input data with a variable numberof timesteps. To introduce masks to your data,use an Embedding layer with themask_zero
parameterset toTrue
.Note on using statefulness in RNNs
You can set RNN layers to be ‘stateful’, which means that the statescomputed for the samples in one batch will be reused as initial statesfor the samples in the next batch. This assumes a onetoone mappingbetween samples in different successive batches.To enable statefulness: specifystateful=True
in the layer constructor. specify a fixed batch size for your model, by passingif sequential model:batch_input_shape=(...)
to the first layer in your model.else for functional model with 1 or more Input layers:batch_shape=(...)
to all the first layers in your model.This is the expected shape of your inputsincluding the batch size.It should be a tuple of integers, e.g.(32, 10, 100)
. specifyshuffle=False
when calling fit().To reset the states of your model, call.reset_states()
on eithera specific layer, or on your entire model.Note on specifying the initial state of RNNs
You can specify the initial state of RNN layers symbolically bycalling them with the keyword argumentinitial_state
. The value ofinitial_state
should be a tensor or list of tensors representingthe initial state of the RNN layer.You can specify the initial state of RNN layers numerically bycallingreset_states
with the keyword argumentstates
. The value ofstates
should be a numpy array or list of numpy arrays representingthe initial state of the RNN layer.Note on passing external constants to RNNs
You can pass “external” constants to the cell using theconstants
keyword argument ofRNN.__call__
(as well asRNN.call
) method. Thisrequires that thecell.call
method accepts the same keyword argumentconstants
. Such constants can be used to condition the celltransformation on additional static inputs (not changing over time),a.k.a. an attention mechanism.Examples
# First, let's define a RNN Cell, as a layer subclass. class MinimalRNNCell(keras.layers.Layer): def __init__(self, units, **kwargs): self.units = units self.state_size = units super(MinimalRNNCell, self).__init__(**kwargs) def build(self, input_shape): self.kernel = self.add_weight(shape=(input_shape[1], self.units), initializer='uniform', name='kernel') self.recurrent_kernel = self.add_weight( shape=(self.units, self.units), initializer='uniform', name='recurrent_kernel') self.built = True def call(self, inputs, states): prev_output = states[0] h = K.dot(inputs, self.kernel) output = h + K.dot(prev_output, self.recurrent_kernel) return output, [output] # Let's use this cell in a RNN layer: cell = MinimalRNNCell(32) x = keras.Input((None, 5)) layer = RNN(cell) y = layer(x) # Here's how to use the cell to build a stacked RNN: cells = [MinimalRNNCell(32), MinimalRNNCell(64)] x = keras.Input((None, 5)) layer = RNN(cells) y = layer(x)

CLASS
¶ alias of
RNN
 cell: A RNN cell instance. A RNN cell is a class that has:

class
conx.layers.
RecurrentLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
RecurrentLayer
Abstract base class for recurrent layers.
Do not use in a model – it’s not a valid layer!Use its children classesLSTM
,GRU
andSimpleRNN
instead.All recurrent layers (LSTM
,GRU
,SimpleRNN
) alsofollow the specifications of this class and acceptthe keyword arguments listed below.Example
# as the first layer in a Sequential model model = Sequential() model.add(LSTM(32, input_shape=(10, 64))) # now model.output_shape == (None, 32) # note: `None` is the batch dimension. # for subsequent layers, no need to specify the input size: model.add(LSTM(16)) # to stack recurrent layers, you must use return_sequences=True # on any recurrent layer that feeds into another recurrent layer. # note that you only need to specify the input size on the first layer. model = Sequential() model.add(LSTM(64, input_dim=64, input_length=10, return_sequences=True)) model.add(LSTM(32, return_sequences=True)) model.add(LSTM(10))
Arguments
 weights: list of Numpy arrays to set as initial weights.
The list should have 3 elements, of shapes:
[(input_dim, output_dim), (output_dim, output_dim), (output_dim,)]
.  return_sequences: Boolean. Whether to return the last output in the output sequence, or the full sequence.
 return_state: Boolean. Whether to return the last state in addition to the output.
 go_backwards: Boolean (default False). If True, process the input sequence backwards and return the reversed sequence.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.
 unroll: Boolean (default False). If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speedup a RNN, although it tends to be more memoryintensive. Unrolling is only suitable for short sequences.
 implementation: one of {0, 1, or 2}.
If set to 0, the RNN will use
an implementation that uses fewer, larger matrix products,
thus running faster on CPU but consuming more memory.
If set to 1, the RNN will use more matrix products,
but smaller ones, thus running slower
(may actually be faster on GPU) while consuming less memory.
If set to 2 (LSTM/GRU only),
the RNN will combine the input gate,
the forget gate and the output gate into a single matrix,
enabling more timeefficient parallelization on the GPU.
 Note: RNN dropout must be shared for all gates, resulting in a slightly reduced regularization.
 input_dim: dimensionality of the input (integer).
This argument (or alternatively, the keyword argument
input_shape
) is required when using this layer as the first layer in a model.  input_length: Length of input sequences, to be specified
when it is constant.
This argument is required if you are going to connect
Flatten
thenDense
layers upstream (without it, the shape of the dense outputs cannot be computed). Note that if the recurrent layer is not the first layer in your model, you would need to specify the input length at the level of the first layer (e.g. via theinput_shape
argument)
Input shapes
3D tensor with shape(batch_size, timesteps, input_dim)
,(Optional) 2D tensors with shape(batch_size, output_dim)
.Output shape
 if
return_state
: a list of tensors. The first tensor is the output. The remaining tensors are the last states, each with shape(batch_size, units)
.  if
return_sequences
: 3D tensor with shape(batch_size, timesteps, units)
.  else, 2D tensor with shape
(batch_size, units)
.
Masking
This layer supports masking for input data with a variable numberof timesteps. To introduce masks to your data,use an Embedding layer with themask_zero
parameterset toTrue
.Note on using statefulness in RNNs
You can set RNN layers to be ‘stateful’, which means that the statescomputed for the samples in one batch will be reused as initial statesfor the samples in the next batch. This assumes a onetoone mappingbetween samples in different successive batches.To enable statefulness: specifystateful=True
in the layer constructor. specify a fixed batch size for your model, by passingif sequential model:batch_input_shape=(...)
to the first layer in your model.else for functional model with 1 or more Input layers:batch_shape=(...)
to all the first layers in your model.This is the expected shape of your inputsincluding the batch size.It should be a tuple of integers, e.g.(32, 10, 100)
. specifyshuffle=False
when calling fit().To reset the states of your model, call.reset_states()
on eithera specific layer, or on your entire model.Note on specifying the initial state of RNNs
You can specify the initial state of RNN layers symbolically bycalling them with the keyword argumentinitial_state
. The value ofinitial_state
should be a tensor or list of tensors representingthe initial state of the RNN layer.You can specify the initial state of RNN layers numerically bycallingreset_states
with the keyword argumentstates
. The value ofstates
should be a numpy array or list of numpy arrays representingthe initial state of the RNN layer.
CLASS
¶ alias of
Recurrent
 weights: list of Numpy arrays to set as initial weights.
The list should have 3 elements, of shapes:

class
conx.layers.
RepeatVectorLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
RepeatVectorLayer
Repeats the input n times.
Example
model = Sequential() model.add(Dense(32, input_dim=32)) # now: model.output_shape == (None, 32) # note: `None` is the batch dimension model.add(RepeatVector(3)) # now: model.output_shape == (None, 3, 32)
Arguments
 n: integer, repetition factor.
Input shape
2D tensor of shape
(num_samples, features)
.Output shape
3D tensor of shape
(num_samples, n, features)
.
CLASS
¶ alias of
RepeatVector

class
conx.layers.
ReshapeLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ReshapeLayer
Reshapes an output to a certain shape.
Arguments
 target_shape: target shape. Tuple of integers. Does not include the batch axis.
Input shape
Arbitrary, although all dimensions in the input shaped must be fixed.Use the keyword argumentinput_shape
(tuple of integers, does not include the batch axis)when using this layer as the first layer in a model.Output shape
(batch_size,) + target_shape
Example
# as first layer in a Sequential model model = Sequential() model.add(Reshape((3, 4), input_shape=(12,))) # now: model.output_shape == (None, 3, 4) # note: `None` is the batch dimension # as intermediate layer in a Sequential model model.add(Reshape((6, 2))) # now: model.output_shape == (None, 6, 2) # also supports shape inference using `1` as dimension model.add(Reshape((1, 2, 2))) # now: model.output_shape == (None, 3, 2, 2)

CLASS
¶ alias of
Reshape

class
conx.layers.
SeparableConv2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SeparableConv2DLayer
Depthwise separable 2D convolution.
Separable convolutions consist in first performinga depthwise spatial convolution(which acts on each input channel separately)followed by a pointwise convolution which mixes together the resultingoutput channels. Thedepth_multiplier
argument controls how manyoutput channels are generated per input channel in the depthwise step.Intuitively, separable convolutions can be understood asa way to factorize a convolution kernel into two smaller kernels,or as an extreme version of an Inception block.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  depth_multiplier: The number of depthwise convolution output
channels
for each input channel.
The total number of depthwise convolution output
channels will be equal to
filterss_in * depth_multiplier
.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 depthwise_initializer: Initializer for the depthwise kernel matrix (see initializers).
 pointwise_initializer: Initializer for the pointwise kernel matrix (see initializers).
 bias_initializer: Initializer for the bias vector (see initializers).
 depthwise_regularizer: Regularizer function applied to the depthwise kernel matrix (see regularizer).
 pointwise_regularizer: Regularizer function applied to the pointwise kernel matrix (see regularizer).
 bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 depthwise_constraint: Constraint function applied to the depthwise kernel matrix (see constraints).
 pointwise_constraint: Constraint function applied to the pointwise kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(batch, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(batch, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.
CLASS
¶ alias of
SeparableConv2D

class
conx.layers.
SeparableConvolution2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SeparableConvolution2DLayer
Depthwise separable 2D convolution.
Separable convolutions consist in first performinga depthwise spatial convolution(which acts on each input channel separately)followed by a pointwise convolution which mixes together the resultingoutput channels. Thedepth_multiplier
argument controls how manyoutput channels are generated per input channel in the depthwise step.Intuitively, separable convolutions can be understood asa way to factorize a convolution kernel into two smaller kernels,or as an extreme version of an Inception block.Arguments
 filters: Integer, the dimensionality of the output space (i.e. the number output of filters in the convolution).
 kernel_size: An integer or tuple/list of 2 integers, specifying the width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
 strides: An integer or tuple/list of 2 integers,
specifying the strides of the convolution along the width and height.
Can be a single integer to specify the same value for
all spatial dimensions.
Specifying any stride value != 1 is incompatible with specifying
any
dilation_rate
value != 1.  padding: one of
"valid"
or"same"
(caseinsensitive).  data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.  depth_multiplier: The number of depthwise convolution output
channels
for each input channel.
The total number of depthwise convolution output
channels will be equal to
filterss_in * depth_multiplier
.  activation: Activation function to use
(see activations).
If you don’t specify anything, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 depthwise_initializer: Initializer for the depthwise kernel matrix (see initializers).
 pointwise_initializer: Initializer for the pointwise kernel matrix (see initializers).
 bias_initializer: Initializer for the bias vector (see initializers).
 depthwise_regularizer: Regularizer function applied to the depthwise kernel matrix (see regularizer).
 pointwise_regularizer: Regularizer function applied to the pointwise kernel matrix (see regularizer).
 bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 depthwise_constraint: Constraint function applied to the depthwise kernel matrix (see constraints).
 pointwise_constraint: Constraint function applied to the pointwise kernel matrix (see constraints).
 bias_constraint: Constraint function applied to the bias vector (see constraints).
Input shape
4D tensor with shape:(batch, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, rows, cols, channels)
if data_format=’channels_last’.Output shape
4D tensor with shape:(batch, filters, new_rows, new_cols)
if data_format=’channels_first’or 4D tensor with shape:(batch, new_rows, new_cols, filters)
if data_format=’channels_last’.rows
andcols
values might have changed due to padding.
CLASS
¶ alias of
SeparableConv2D

class
conx.layers.
SimpleRNNCellLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SimpleRNNCellLayer
Cell class for SimpleRNN.
Arguments
 units: Positive integer, dimensionality of the output space.
 activation: Activation function to use
(see activations).
If you pass None, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
 recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.

CLASS
¶ alias of
SimpleRNNCell

class
conx.layers.
SimpleRNNLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SimpleRNNLayer
Fullyconnected RNN where the output is to be fed back to input.
Arguments
 units: Positive integer, dimensionality of the output space.
 activation: Activation function to use
(see activations).
If you pass None, no activation is applied
(ie. “linear” activation:
a(x) = x
).  use_bias: Boolean, whether the layer uses a bias vector.
 kernel_initializer: Initializer for the
kernel
weights matrix, used for the linear transformation of the inputs. (see initializers).  recurrent_initializer: Initializer for the
recurrent_kernel
weights matrix, used for the linear transformation of the recurrent state. (see initializers).  bias_initializer: Initializer for the bias vector (see initializers).
 kernel_regularizer: Regularizer function applied to
the
kernel
weights matrix (see regularizer).  recurrent_regularizer: Regularizer function applied to
the
recurrent_kernel
weights matrix (see regularizer).  bias_regularizer: Regularizer function applied to the bias vector (see regularizer).
 activity_regularizer: Regularizer function applied to the output of the layer (its “activation”). (see regularizer).
 kernel_constraint: Constraint function applied to
the
kernel
weights matrix (see constraints).  recurrent_constraint: Constraint function applied to
the
recurrent_kernel
weights matrix (see constraints).  bias_constraint: Constraint function applied to the bias vector (see constraints).
 dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the inputs.
 recurrent_dropout: Float between 0 and 1. Fraction of the units to drop for the linear transformation of the recurrent state.
 return_sequences: Boolean. Whether to return the last output. in the output sequence, or the full sequence.
 return_state: Boolean. Whether to return the last state in addition to the output.
 go_backwards: Boolean (default False). If True, process the input sequence backwards and return the reversed sequence.
 stateful: Boolean (default False). If True, the last state for each sample at index i in a batch will be used as initial state for the sample of index i in the following batch.
 unroll: Boolean (default False). If True, the network will be unrolled, else a symbolic loop will be used. Unrolling can speedup a RNN, although it tends to be more memoryintensive. Unrolling is only suitable for short sequences.

CLASS
¶ alias of
SimpleRNN

class
conx.layers.
SpatialDropout1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SpatialDropout1DLayer
Spatial 1D version of Dropout.
This version performs the same function as Dropout, however it dropsentire 1D feature maps instead of individual elements. If adjacent frameswithin feature maps are strongly correlated (as is normally the case inearly convolution layers) then regular dropout will not regularize theactivations and will otherwise just result in an effective learning ratedecrease. In this case, SpatialDropout1D will help promote independencebetween feature maps and should be used instead.Arguments
 rate: float between 0 and 1. Fraction of the input units to drop.
Input shape
3D tensor with shape:(samples, timesteps, channels)
Output shape
Same as input
References

CLASS
¶ alias of
SpatialDropout1D

class
conx.layers.
SpatialDropout2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SpatialDropout2DLayer
Spatial 2D version of Dropout.
This version performs the same function as Dropout, however it dropsentire 2D feature maps instead of individual elements. If adjacent pixelswithin feature maps are strongly correlated (as is normally the case inearly convolution layers) then regular dropout will not regularize theactivations and will otherwise just result in an effective learning ratedecrease. In this case, SpatialDropout2D will help promote independencebetween feature maps and should be used instead.Arguments
 rate: float between 0 and 1. Fraction of the input units to drop.
 data_format: ‘channels_first’ or ‘channels_last’.
In ‘channels_first’ mode, the channels dimension
(the depth) is at index 1,
in ‘channels_last’ mode is it at index 3.
It defaults to the
image_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
4D tensor with shape:(samples, channels, rows, cols)
if data_format=’channels_first’or 4D tensor with shape:(samples, rows, cols, channels)
if data_format=’channels_last’.Output shape
Same as input
References

CLASS
¶ alias of
SpatialDropout2D

class
conx.layers.
SpatialDropout3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SpatialDropout3DLayer
Spatial 3D version of Dropout.
This version performs the same function as Dropout, however it dropsentire 3D feature maps instead of individual elements. If adjacent voxelswithin feature maps are strongly correlated (as is normally the case inearly convolution layers) then regular dropout will not regularize theactivations and will otherwise just result in an effective learning ratedecrease. In this case, SpatialDropout3D will help promote independencebetween feature maps and should be used instead.Arguments
 rate: float between 0 and 1. Fraction of the input units to drop.
 data_format: ‘channels_first’ or ‘channels_last’.
In ‘channels_first’ mode, the channels dimension (the depth)
is at index 1, in ‘channels_last’ mode is it at index 4.
It defaults to the
image_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
5D tensor with shape:(samples, channels, dim1, dim2, dim3)
if data_format=’channels_first’or 5D tensor with shape:(samples, dim1, dim2, dim3, channels)
if data_format=’channels_last’.Output shape
Same as input
References

CLASS
¶ alias of
SpatialDropout3D

class
conx.layers.
StackedRNNCellsLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
StackedRNNCellsLayer
Wrapper allowing a stack of RNN cells to behave as a single cell.
Used to implement efficient stacked RNNs.
Arguments
 cells: List of RNN cell instances.
Examples
cells = [ keras.layers.LSTMCell(output_dim), keras.layers.LSTMCell(output_dim), keras.layers.LSTMCell(output_dim), ] inputs = keras.Input((timesteps, input_dim)) x = keras.layers.RNN(cells)(inputs)

CLASS
¶ alias of
StackedRNNCells

class
conx.layers.
SubtractLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
SubtractLayer
Layer that subtracts two inputs.
It takes as input a list of tensors of size 2,both of the same shape, and returns a single tensor, (inputs[0]  inputs[1]),also of the same shape.Examples
import keras input1 = keras.layers.Input(shape=(16,)) x1 = keras.layers.Dense(8, activation='relu')(input1) input2 = keras.layers.Input(shape=(32,)) x2 = keras.layers.Dense(8, activation='relu')(input2) # Equivalent to subtracted = keras.layers.subtract([x1, x2]) subtracted = keras.layers.Subtract()([x1, x2]) out = keras.layers.Dense(4)(subtracted) model = keras.models.Model(inputs=[input1, input2], outputs=out)

CLASS
¶ alias of
Subtract


class
conx.layers.
ThresholdedReLULayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ThresholdedReLULayer
Thresholded Rectified Linear Unit.
It follows:f(x) = x for x > theta
,f(x) = 0 otherwise
.Input shape
Arbitrary. Use the keyword argumentinput_shape
(tuple of integers, does not include the samples axis)when using this layer as the first layer in a model.Output shape
Same shape as the input.
Arguments
 theta: float >= 0. Threshold location of activation.
References

CLASS
¶ alias of
ThresholdedReLU

class
conx.layers.
UpSampling1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
UpSampling1DLayer
Upsampling layer for 1D inputs.
Repeats each temporal step
size
times along the time axis.Arguments
 size: integer. Upsampling factor.
Input shape
3D tensor with shape:
(batch, steps, features)
.Output shape
3D tensor with shape:
(batch, upsampled_steps, features)
.
CLASS
¶ alias of
UpSampling1D

class
conx.layers.
UpSampling2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
UpSampling2DLayer
Upsampling layer for 2D inputs.
Repeats the rows and columns of the databy size[0] and size[1] respectively.Arguments
 size: int, or tuple of 2 integers. The upsampling factors for rows and columns.
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
4D tensor with shape:
 If
data_format
is"channels_last"
:(batch, rows, cols, channels)
 If
data_format
is"channels_first"
:(batch, channels, rows, cols)
Output shape
4D tensor with shape:
 If
data_format
is"channels_last"
:(batch, upsampled_rows, upsampled_cols, channels)
 If
data_format
is"channels_first"
:(batch, channels, upsampled_rows, upsampled_cols)

CLASS
¶ alias of
UpSampling2D

class
conx.layers.
UpSampling3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
UpSampling3DLayer
Upsampling layer for 3D inputs.
Repeats the 1st, 2nd and 3rd dimensionsof the data by size[0], size[1] and size[2] respectively.Arguments
 size: int, or tuple of 3 integers. The upsampling factors for dim1, dim2 and dim3.
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
5D tensor with shape:
 If
data_format
is"channels_last"
:(batch, dim1, dim2, dim3, channels)
 If
data_format
is"channels_first"
:(batch, channels, dim1, dim2, dim3)
Output shape
5D tensor with shape:
 If
data_format
is"channels_last"
:(batch, upsampled_dim1, upsampled_dim2, upsampled_dim3, channels)
 If
data_format
is"channels_first"
:(batch, channels, upsampled_dim1, upsampled_dim2, upsampled_dim3)

CLASS
¶ alias of
UpSampling3D

class
conx.layers.
WrapperLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
WrapperLayer
Abstract wrapper base class.
Wrappers take another layer and augment it in various ways.Do not use this class as a layer, it is only an abstract base class.Two usable wrappers are theTimeDistributed
andBidirectional
wrappers.Arguments
 layer: The layer to be wrapped.

CLASS
¶ alias of
Wrapper

class
conx.layers.
ZeroPadding1DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ZeroPadding1DLayer
Zeropadding layer for 1D input (e.g. temporal sequence).
Arguments
 padding: int, or tuple of int (length 2), or dictionary.
 If int: How many zeros to add at the beginning and end of the padding dimension (axis 1).
 If tuple of int (length 2):
How many zeros to add at the beginning and at the end of
the padding dimension (
(left_pad, right_pad)
).
Input shape
3D tensor with shape
(batch, axis_to_pad, features)
Output shape
3D tensor with shape
(batch, padded_axis, features)

CLASS
¶ alias of
ZeroPadding1D
 padding: int, or tuple of int (length 2), or dictionary.

class
conx.layers.
ZeroPadding2DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ZeroPadding2DLayer
Zeropadding layer for 2D input (e.g. picture).
This layer can add rows and columns of zerosat the top, bottom, left and right side of an image tensor.Arguments
 padding: int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.
 If int: the same symmetric padding is applied to width and height.
 If tuple of 2 ints:
interpreted as two different
symmetric padding values for height and width:
(symmetric_height_pad, symmetric_width_pad)
.  If tuple of 2 tuples of 2 ints:
interpreted as
((top_pad, bottom_pad), (left_pad, right_pad))
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, height, width, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, height, width)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
4D tensor with shape:
 If
data_format
is"channels_last"
:(batch, rows, cols, channels)
 If
data_format
is"channels_first"
:(batch, channels, rows, cols)
Output shape
4D tensor with shape:
 If
data_format
is"channels_last"
:(batch, padded_rows, padded_cols, channels)
 If
data_format
is"channels_first"
:(batch, channels, padded_rows, padded_cols)

CLASS
¶ alias of
ZeroPadding2D
 padding: int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.

class
conx.layers.
ZeroPadding3DLayer
(name, *args, **params)¶ Bases:
conx.layers._BaseLayer
ZeroPadding3DLayer
Zeropadding layer for 3D data (spatial or spatiotemporal).
Arguments
 padding: int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.
 If int: the same symmetric padding is applied to width and height.
 If tuple of 2 ints:
interpreted as two different
symmetric padding values for height and width:
(symmetric_dim1_pad, symmetric_dim2_pad, symmetric_dim3_pad)
.  If tuple of 2 tuples of 2 ints:
interpreted as
((left_dim1_pad, right_dim1_pad), (left_dim2_pad, right_dim2_pad), (left_dim3_pad, right_dim3_pad))
 data_format: A string,
one of
channels_last
(default) orchannels_first
. The ordering of the dimensions in the inputs.channels_last
corresponds to inputs with shape(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)
whilechannels_first
corresponds to inputs with shape(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)
. It defaults to theimage_data_format
value found in your Keras config file at~/.keras/keras.json
. If you never set it, then it will be “channels_last”.
Input shape
5D tensor with shape:
 If
data_format
is"channels_last"
:(batch, first_axis_to_pad, second_axis_to_pad, third_axis_to_pad, depth)
 If
data_format
is"channels_first"
:(batch, depth, first_axis_to_pad, second_axis_to_pad, third_axis_to_pad)
Output shape
5D tensor with shape:
 If
data_format
is"channels_last"
:(batch, first_padded_axis, second_padded_axis, third_axis_to_pad, depth)
 If
data_format
is"channels_first"
:(batch, depth, first_padded_axis, second_padded_axis, third_axis_to_pad)

CLASS
¶ alias of
ZeroPadding3D
 padding: int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.
4.1.5. conx.utils module¶

class
conx.utils.
Experiment
(name)[source]¶ Bases:
object
Run a series of experiments.
function() should take any options, and return a network.
>>> from conx import Network >>> def function(optimizer, activation, **options): ... net = Network("XOR", 2, 2, 1, activation=activation) ... net.compile(error="mse", optimizer=optimizer) ... net.dataset.add_by_function(2, (0, 4), "binary", lambda i,v: [int(sum(v) == len(v))]) ... net.train(report_rate=100, verbose=0, **options) ... category = "%s%s" % (optimizer, activation) ... return category, net >>> exp = Experiment("XOR") >>> exp.run(function, ... epochs=[5], ... accuracy=[0.8], ... tolerance=[0.2], ... optimizer=["adam", "sgd"], ... activation=["sigmoid", "relu"], ... dir="/tmp/") >>> len(exp.results) 4 >>> exp.plot("loss", interactive=False) <IPython.core.display.SVG object> >>> exp.apply(lambda category, exp_name: (category, exp_name)) [('adamsigmoid', '/tmp/XOR0000100001'), ('sgdsigmoid', '/tmp/XOR0000100002'), ('adamrelu', '/tmp/XOR0000100003'), ('sgdrelu', '/tmp/XOR0000100004')]

class
conx.utils.
PCA
(states, dim=2, solver='randomized')[source]¶ Bases:
object
Compute the Prinicpal Component Analysis for the points in a multidimensional space.
Example
>>> data = [ ... [0.00, 0.00, 0.00], ... [0.25, 0.25, 0.25], ... [0.50, 0.50, 0.50], ... [0.75, 0.75, 0.75], ... [1.00, 1.00, 1.00], ... ] >>> pca = PCA(data) >>> new_data = pca.transform(data) >>> len(new_data) 5

transform
(vectors)[source]¶ >>> from conx import Network >>> net = Network("Example", 2, 2, 1) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.load([ ... [[0, 0], [0], "0"], ... [[0, 1], [1], "1"], ... [[1, 0], [1], "1"], ... [[1, 1], [0], "0"], ... ]) >>> states = [net.propagate_to("hidden", input) for input in net.dataset.inputs] >>> pca = PCA(states) >>> new_states = pca.transform(states) >>> len(new_states) 4

transform_network_bank
(network, bank, label_index=0, tolerance=None, test=True)[source]¶ >>> from conx import Network >>> net = Network("Example", 2, 2, 1) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.load([ ... [[0, 0], [0], "0"], ... [[0, 1], [1], "1"], ... [[1, 0], [1], "1"], ... [[1, 1], [0], "0"], ... ]) >>> states = [net.propagate_to("hidden", input) for input in net.dataset.inputs] >>> pca = PCA(states) >>> results = pca.transform_network_bank(net, "hidden") >>> sum([len(vectors) for (label, vectors) in results["data"]]) 4 >>> "xmin" in results True >>> "xmax" in results True >>> "ymin" in results True >>> "ymax" in results True

transform_one
(vector)[source]¶ Transform a vector into the PCA of the trained states.
>>> from conx import Network >>> net = Network("Example", 2, 2, 1) >>> net.compile(error="mse", optimizer="adam") >>> net.dataset.load([ ... [[0, 0], [0], "0"], ... [[0, 1], [1], "1"], ... [[1, 0], [1], "1"], ... [[1, 1], [0], "0"], ... ]) >>> states = [net.propagate_to("hidden", input) for input in net.dataset.inputs] >>> pca = PCA(states) >>> new_state = pca.transform_one(states[0]) >>> len(new_state) 2


conx.utils.
all_same
(iterator)[source]¶ Are there more than one item, and all the same?
>>> all_same([int, int, int]) True
>>> all_same([int, float, int]) False

conx.utils.
argmax
(seq)[source]¶ Find the index of the maximum value in seq.
>>> argmax([0.1, 0.2, 0.3, 0.1]) 2

conx.utils.
atype
(dtype)[source]¶ Given a numpy dtype, return the associated Python type. If unable to determine, just return the dtype.kind code.
>>> atype(np.float64(23).dtype) <class 'numbers.Number'>

conx.utils.
autoname
(index, sizes)[source]¶ Given an index and list of sizes, return a name for the layer.
>>> autoname(0, sizes=4) 'input' >>> autoname(1, sizes=4) 'hidden1' >>> autoname(2, sizes=4) 'hidden2' >>> autoname(3, sizes=4) 'output'

conx.utils.
binary
(i, width)[source]¶ >>> binary(0, 5) [0, 0, 0, 0, 0]
>>> binary(15, 4) [1, 1, 1, 1]
>>> binary(14, 4) [1, 1, 1, 0]

conx.utils.
choice
(seq=None, p=None)[source]¶ Get a random choice from sequence, optionally given a probability distribution.
>>> choice(1) 0
>>> choice([42]) 42
>>> choice("abcde", p=[0, 1, 0, 0, 0]) 'b'
>>> choice(p=[0, 0, 1, 0, 0]) 2

conx.utils.
collapse
(item)[source]¶ For any repeated structure, return [struct, count].
>>> collapse([[int, int, int], [float, float]]) [[<class 'int'>, 3], [<class 'float'>, 2]]

conx.utils.
find_path
(net, start_layer, end_layer)[source]¶ Given a conx network, a start layer, and an ending layer, find the path between them.

conx.utils.
format_collapse
(ttype, dims)[source]¶ Given a type and a tuple of dimensions, return a struct of [[[ttype, dims[1]], dims[2]], …]
>>> format_collapse(int, (1, 2, 3)) [[[<class 'int'>, 3], 2], 1]

conx.utils.
frange
(start, stop=None, step=1.0)[source]¶ Like range(), but with floats.
May not be exactly correct due to rounding issues.
>>> len(frange(1, 1, .1)) 20

conx.utils.
get_device
()[source]¶ Returns ‘cpu’ or ‘gpu’ indicating which device the system will use.
>>> get_device() in ["gpu", "cpu"] True

conx.utils.
get_form
(item)[source]¶ First, get the types of all items, and then collapse repeated structures.
>>> get_form([1, [2, 5, 6], 3]) [<class 'numbers.Number'>, [<class 'numbers.Number'>, 3], <class 'numbers.Number'>]

conx.utils.
get_shape
(form)[source]¶ Given a form, format it in [type, dimension] format.
>>> get_shape(get_form([[0.00], [0.00]])) (<class 'numbers.Number'>, [2, 1])

conx.utils.
get_symbol
(label: str, symbols: dict = None, default='o') → str[source]¶ Get a matplotlib symbol from a label.
Possible shape symbols:
 ‘‘ solid line style
 ‘–’ dashed line style
 ‘.’ dashdot line style
 ‘:’ dotted line style
 ‘.’ point marker
 ‘,’ pixel marker
 ‘o’ circle marker
 ‘v’ triangle_down marker
 ‘^’ triangle_up marker
 ‘<’ triangle_left marker
 ‘>’ triangle_right marker
 ‘1’ tri_down marker
 ‘2’ tri_up marker
 ‘3’ tri_left marker
 ‘4’ tri_right marker
 ‘s’ square marker
 ‘p’ pentagon marker
 ‘*’ star marker
 ‘h’ hexagon1 marker
 ‘H’ hexagon2 marker
 ‘+’ plus marker
 ‘x’ x marker
 ‘D’ diamond marker
 ‘d’ thin_diamond marker
 ‘’ vline marker
 ‘_’ hline marker
In addition, the shape symbol can be preceded by the following color abbreviations:
 ‘b’ blue
 ‘g’ green
 ‘r’ red
 ‘c’ cyan
 ‘m’ magenta
 ‘y’ yellow
 ‘k’ black
 ‘w’ white
Examples
>>> get_symbol("Apple") 'o' >>> get_symbol("Apple", {'Apple': 'x'}) 'x' >>> get_symbol("Banana", {'Apple': 'x'}) 'o'

conx.utils.
is_collapsed
(item)[source]¶ Is this a collapsed item?
>>> is_collapsed([int, 3]) True
>>> is_collapsed([int, int, int]) False

conx.utils.
onehot
(i, width)[source]¶ >>> onehot(0, 5) [1, 0, 0, 0, 0]
>>> onehot(3, 5) [0, 0, 0, 1, 0]

conx.utils.
plot
(data=[], width=8.0, height=4.0, xlabel='', ylabel='', title='', label='', symbols=None, ymin=None, xmin=None, ymax=None, xmax=None, interactive=True)[source]¶ >>> p = plot(["Error", [1, 2, 4, 6, 1, 2, 3]], ... ylabel="error", ... xlabel="hello", interactive=False) >>> p <IPython.core.display.SVG object> >>> p = plot([["Error", [1, 2, 4, 6, 1, 2, 3]]], ... ylabel="error", ... xlabel="hello", interactive=False) >>> p <IPython.core.display.SVG object>

conx.utils.
plot_f
(f, frange=(1, 1, 0.1), symbol='o', xlabel='', ylabel='', title='', interactive=True)[source]¶ Plot a function.
>>> plot_f(lambda x: x, frange=(1, 1, .1), interactive=False) <IPython.core.display.SVG object>

conx.utils.
rescale_numpy_array
(a, old_range, new_range, new_dtype, truncate=False)[source]¶ Given a numpy array, old min/max, a new min/max and a numpy type, create a new numpy array that scales the old values into the new_range.
>>> import numpy as np >>> rescale_numpy_array(np.array([0.1, 0.2, 0.3]), (0, 1), (0.5, 1.), float) array([ 0.55, 0.6 , 0.65])

conx.utils.
reset_plt_param
(setting)[source]¶ Reset the matplotlib setting to its default.
>>> original = plt.rcParams["figure.figsize"] >>> set_plt_param("figure.figsize", [5, 5]) >>> original == plt.rcParams["figure.figsize"] False >>> [5, 5] == plt.rcParams["figure.figsize"] True >>> reset_plt_param("figure.figsize") >>> original == plt.rcParams["figure.figsize"] True

conx.utils.
scatter
(data=[], width=6.0, height=6.0, xlabel='', ylabel='', title='', label='', symbols=None, ymin=None, xmin=None, ymax=None, xmax=None, interactive=True)[source]¶ Create a scatter plot with series of (x,y) data.
>>> scatter(["Test 1", [(0,4), (2,3), (1,2)]], interactive=False) <IPython.core.display.SVG object>

conx.utils.
set_plt_param
(setting, value)[source]¶ Set the matplotlib setting to a new value.
>>> original = plt.rcParams["font.size"] >>> set_plt_param("font.size", 8.0) >>> original == plt.rcParams["font.size"] False >>> 8.0 == plt.rcParams["font.size"] True >>> reset_plt_param("font.size") >>> original == plt.rcParams["font.size"] True

conx.utils.
shape
(item)[source]¶ Shortcut for get_shape(get_form(item)).
>>> shape([1]) (1,) >>> shape([1, 2]) (2,) >>> shape([[1, 2, 3], [4, 5, 6]]) (2, 3)

conx.utils.
topological_sort
(net, layers)[source]¶ Given a conx network and list of layers, produce a topological sorted list, from input(s) to output(s).

conx.utils.
types
(item)[source]¶ Get the types of (possibly) nested list(s), and collapse if possible.
>>> types(0) <class 'numbers.Number'>
>>> types([0, 1, 2]) [<class 'numbers.Number'>, 3]

conx.utils.
valid_shape
(x)[source]¶ Is this a valid shape for Keras layers?
>>> valid_shape(1) True >>> valid_shape(None) True >>> valid_shape((1,)) True >>> valid_shape((None, )) True
4.1.6. conx.wdigets module¶

class
conx.widgets.
CameraWidget
(*args, **kwargs)[source]¶ Bases:
ipywidgets.widgets.domwidget.DOMWidget
Represents a media source.

audio
¶ A boolean (True, False) trait.

image
¶ A trait for unicode strings.

image_count
¶ An int trait.

video
¶ A boolean (True, False) trait.


class
conx.widgets.
Dashboard
(net, width='95%', height='550px', play_rate=0.5)[source]¶ Bases:
ipywidgets.widgets.widget_box.VBox
Build the dashboard for Jupyter widgets. Requires running in a notebook/jupyterlab.