Caffe2 - Python API
A deep learning, cross platform ML framework
parameter_info.py
1 from __future__ import absolute_import
2 from __future__ import division
3 from __future__ import print_function
4 from __future__ import unicode_literals
5 
6 from caffe2.python import core
7 
8 import numpy as np
9 
10 
11 class ParameterTags(object):
12  BIAS = 'BIAS'
13  WEIGHT = 'WEIGHT'
14  COMPUTED_PARAM = 'COMPUTED_PARAM'
15 
16 
17 class ParameterInfo(object):
18 
19  def __init__(
20  self, param_id, param, key=None, shape=None, length=None,
21  grad=None, blob_copy=None):
22  assert isinstance(param, core.BlobReference)
23  self.param_id = param_id
24  self.name = str(param)
25  self.blob = param
26  self.key = key
27  self.shape = shape
28  self.size = None if shape is None else np.prod(shape)
29  self.length = max(1, length if length is not None else 1)
30  self.grad = grad
31  self._cloned_init_net = None
32  # Optionally store equivalent copies of the blob
33  # in different precisions (i.e. half and float copies)
34  # stored as a dict of TensorProto.DataType -> BlobReference
35  self.blob_copy = blob_copy
36  # each param_info can have its own optimizer. It can be set within
37  # OptimizerContext (caffe2/python/optimizer.py)
38  self._optimizer = None
39 
40  @property
41  def parameter(self):
42  return self.blob
43 
44  @property
45  def optimizer(self):
46  return self._optimizer
47 
48  @optimizer.setter
49  def optimizer(self, value):
50  assert self._optimizer is None, "optimizer has already been set"
51  self._optimizer = value
52 
53  def __str__(self):
54  return self.name