Caffe2 - Python API
A deep learning, cross platform ML framework
Packages
Classes
Files
C++ API
Python API
GitHub
File List
caffe2
python
layers
constant_weight.py
1
# @package constant_weight
2
# Module caffe2.fb.python.layers.constant_weight
3
from
__future__
import
absolute_import
4
from
__future__
import
division
5
from
__future__
import
print_function
6
from
__future__
import
unicode_literals
7
8
from
caffe2.python
import
schema
9
from
caffe2.python.layers.layers
import
ModelLayer
10
import
numpy
as
np
11
12
13
class
ConstantWeight
(
ModelLayer
):
14
def
__init__(
15
self,
16
model,
17
input_record,
18
weights=
None
,
19
name=
'constant_weight'
,
20
**kwargs
21
):
22
super(ConstantWeight,
23
self).__init__(model, name, input_record, **kwargs)
24
self.
output_schema
=
schema.Scalar
(
25
np.float32, self.
get_next_blob_reference
(
'constant_weight'
)
26
)
27
self.
data
= self.input_record.field_blobs()
28
self.
num
= len(self.
data
)
29
weights = (
30
weights
if
weights
is
not
None
else
31
[1. / self.
num
for
_
in
range(self.
num
)]
32
)
33
assert
len(weights) == self.
num
34
self.
weights
= [
35
self.model.add_global_constant(
36
'%s_weight_%d'
% (self.
name
, i), float(weights[i])
37
)
for
i
in
range(self.
num
)
38
]
39
40
def
add_ops(self, net):
41
net.WeightedSum(
42
[b
for
x_w_pair
in
zip(self.
data
, self.
weights
)
for
b
in
x_w_pair],
43
self.
output_schema
()
44
)
caffe2.python.layers.constant_weight.ConstantWeight.output_schema
output_schema
Definition:
constant_weight.py:24
caffe2.python.layers.layers.ModelLayer.name
name
Definition:
layers.py:220
caffe2.python.layers.constant_weight.ConstantWeight.data
data
Definition:
constant_weight.py:27
caffe2.python.layers.layers.ModelLayer
Definition:
layers.py:195
caffe2.python.layers.layers.ModelLayer.get_next_blob_reference
def get_next_blob_reference(self, name)
Definition:
layers.py:349
caffe2.python.layers.constant_weight.ConstantWeight
Definition:
constant_weight.py:13
caffe2.python
Definition:
__init__.py:1
caffe2.python.layers.constant_weight.ConstantWeight.num
num
Definition:
constant_weight.py:28
caffe2.python.schema.Scalar
Definition:
schema.py:580
caffe2.python.layers.layers
Definition:
layers.py:1
caffe2.python.layers.constant_weight.ConstantWeight.weights
weights
Definition:
constant_weight.py:34
Generated on Thu Mar 21 2019 13:06:36 for Caffe2 - Python API by
1.8.11