Caffe2 - Python API
A deep learning, cross platform ML framework
dot_product.py
1 
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 core, schema
9 from caffe2.python.layers.layers import (
10  ModelLayer,
11 )
12 
13 
14 class DotProduct(ModelLayer):
15 
16  def __init__(self, model, input_record, name='dot_product', **kwargs):
17  super(DotProduct, self).__init__(model, name, input_record, **kwargs)
18  assert isinstance(input_record, schema.Struct),\
19  "Incorrect input type. Excpected Struct, but received: {0}".\
20  format(input_record)
21  assert len(input_record.get_children()) == 2, (
22  "DotProduct accept 2 inputs")
23  assert len(set(input_record.field_types())) == 1, (
24  "Inputs should be of the same field type")
25 
26  for field_name, field_type in input_record.fields.items():
27  assert isinstance(field_type, schema.Scalar),\
28  "Incorrect input type for {}. Excpected Scalar, but got: {}".\
29  format(field_name, field_type)
30 
32  (input_record.field_types()[0].base, ()),
33  model.net.NextScopedBlob(name + '_output'))
34 
35  def add_ops(self, net):
36  net.DotProduct(
37  self.input_record.field_blobs(),
38  self.output_schema(),
39  )
def input_record(self)
Definition: layers.py:149