Net

Quick Reference

List Brief
Net.copy_from Copy the parameters from the binary proto file.
Net.forward Forward Pass.
Net.backward Backward Pass.
Net.function Forward + Backward Pass.
Net.save Save the parameters into a binary file.
Net.blobs Return the blobs.
Net.params Return the parameters.
Net.trainable_params Return the trainable parameters.
Net.inputs Return the inputs of net.
Net.outputs Return the outputs of net.

API Reference

class dragon.vm.caffe.net.Net(*args)

Net supports the most exporting interfaces of caffe.Net.

We implement it completely in the python environment, which provides conveniences,

especially when extending the modern architectures of Convolution Networks,

__init__(*args)

Construct a Net by the proto_txt file.

Parameters:
  • proto_txt (str) – The path of .proto_txt file.
  • model (str) – (Optional) The path of the .caffemodel file.
  • phase (str) – The phase, TRAIN or TEST.
Returns:

The net.

Return type:

Net

Examples

>>> train_net = Net('train.prototxt', 'TRAIN')
>>> test_net = Net('test.prototxt', 'snapshot/xxx.caffemodel', 'TEST')

References

NetInit(proto_txt, phase) - Construct a Net.

NetInitLoad(proto_txt, model, phase) - Construct a Net and load the model.

NetInit(proto_txt, phase='TRAIN')

Construct a Net by the proto_txt file.

Parameters:
  • proto_txt (str) – The path of proto_txt file.
  • phase (str) – The phase, TRAIN or TEST.
Returns:

The net.

Return type:

Net

References

The implementation of Net_Init(_caffe.cpp, L109).

NetInitLoad(proto_txt, model, phase='TRAIN')

Construct a Net by the proto_txt file.

Parameters:
  • proto_txt (str) – The path of proto_txt file.
  • model (str) – (Optional) The path of the .caffemodel file.
  • phase (str) – The phase, TRAIN or TEST.
Returns:

The net.

Return type:

Net

References

The implementation of Net_Init_Load(_caffe.cpp, L137).

FilterLayer(LayerParameter)

Filter the layers.

Parameters:LayerParameter (LayerParameter) – The parameter of Layer.
Returns:Whether this layer should be keep.
Return type:boolean

References

The implementation of FilterNet(net.cpp, L259).

Setup()

Setup the net.

Returns:
Return type:None

References

The implementation of Init(net.cpp, L44).

CheckBackward(layer_param)

Generate losses and trainable blobs.

Parameters:layer_param (LayerParameter) – The parameter of Layer.
Returns:
Return type:None

References

The implementation of Init(net.cpp, L44).

function()

Returns the function the ForwardBackward.

Returns:The function.
Return type:lambda

See also

theano.function(*args, **kwargs) - How to make a graph. [Theano Style]

References

The implementation of ForwardBackward(net.cpp, L85).

copy_from(model)

Copy the parameters from the binary proto file. [PyCaffe Style]

Parameters:model (str) – The path of the .caffemodel file.

See also

workspace.Restore(*args, **kwargs) - How to restore tensors from a file.

References

The implementation of CopyTrainedLayersFromBinaryProto(net.cpp, L780).

forward(**kwargs)

Forward pass. [PyCaffe Style]

Parameters:inputs (dict, optional) – The blobs to feed before.
Returns:The outputs of the net.
Return type:sequence of Tensor

References

The implementation of Net_forward(pycaffe.py, L88).

forward_v2(**kwargs)

Forward pass while silencing all net outputs.

Parameters:inputs (dict, optional) – The blobs to feed before.
Returns:
Return type:None
backward(**kwargs)

Backward pass. [PyCaffe Style]

Parameters:diffs (dict, optional) – The diffs to feed before.
Returns:
Return type:None

References

The implementation of Net_backward(pycaffe.py, L137).

save(filename)

Save the parameters into a binary file. [PyCaffe Style]

Parameters:filename (str) – The path of model file.
Returns:
Return type:None

See also

workspace.Snapshot(*args, **kwargs) - How to snapshot tensors into a file.

References

The implementation of Net_Save(_caffe.cpp, L153).

blobs

Return the blobs. [PyCaffe Style]

Returns:The format of dict is: <blob_name, blob>.
Return type:dict

Examples

>>> data = self..blobs['conv1'].data
>>> diff = self.blobs['conv1'].diff

References

The implementation of Net_blobs(pycaffe.py, L25).

params

Return the parameters. [PyCaffe Style]

Returns:The format of dict is: <layer_name, list of blobs>.
Return type:dict

Examples

>>> weights = self..params['conv1'][0].data
>>> bias = self.params['conv1'][1].data

References

The implementation of Net_params(pycaffe.py, L58).

losses

Return the losses of this net.

Returns:The trainable parameters.
Return type:sequence of Tensor
trainable_variables

Return the trainable variables of this net.

Returns:The trainable parameters.
Return type:sequence of Tensor
variables

Return a list of parameters for snapshot. [PyCaffe Style]

Returns:The list of all parameters.
Return type:sequence of Tensor

Examples

>>> import dragon
>>> dragon.workspace.Snapshot(self.variables, filename='xxx', suffix='.caffeomdel')
inputs

Return the inputs of net. [PyCaffe Style]

Returns:The inputs.
Return type:sequence of str

References

The implementation of Net_inputs(pycaffe.py, L73).

outputs

Return the outputs of net. [PyCaffe Style]

Returns:The outputs
Return type:sequence of str

References

The implementation of Net_outputs(pycaffe.py, L81).

class dragon.vm.caffe.net.PartialNet(*args, **kwargs)

Construct a Net by explicitly injecting tensors.

Examples

>>> import dragon
>>> net = PartialNet('xxx.proto_txt', 'TEST', **{'blob_name': dragon.Tensor().Variable()})