3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
8 from caffe2.python
import core, schema, scope, workspace
9 from caffe2.python.layers.layers
import (
12 import caffe2.proto.caffe2_pb2
as caffe2_pb2
16 logger = logging.getLogger(__name__)
17 logger.setLevel(logging.INFO)
22 def __init__(self, model, input_record, output_names_or_num, function,
23 name='functional', **kwargs):
27 super(Functional, self).__init__(model, name, input_record, **kwargs)
31 if isinstance(output_names_or_num, int):
35 if not isinstance(output_names_or_num, list):
36 output_names_or_num = [output_names_or_num]
37 out_tuple = [(out, np.void)
for out
in output_names_or_num]
46 type_net =
core.Net(
'_temp_type_and_shape_inference_net')
51 for i
in range(num_outputs):
53 if blob
not in types
or blob
not in shapes:
56 if shapes[blob] == []:
59 elif shapes[blob][0] == 0:
60 shape = tuple(shapes[blob][1:])
62 logger.warning(
"unexpeced shape: {}".format(shapes[blob]))
70 if types[blob] == caffe2_pb2.TensorProto.DOUBLE:
71 dtype = (np.float64, shape)
72 elif types[blob] == caffe2_pb2.TensorProto.FLOAT:
73 dtype = (np.float32, shape)
74 elif types[blob] == caffe2_pb2.TensorProto.INT32:
75 dtype = (np.int32, shape)
76 elif types[blob] == caffe2_pb2.TensorProto.INT64:
77 dtype = (np.int64, shape)
81 except TypeError
as ex:
83 logger.warning(str(ex))
87 "Type inference had problems for layer: {}".format(self.
name))
89 def add_ops(self, net):
def NewRecord(net, schema)
def RawTuple(num_fields, name_prefix='field')
def InferShapesAndTypes(nets, blob_dimensions=None)
def NameScope(prefix, reset=False)
def InitEmptyRecord(net, schema_or_record, enforce_types=False)