Caffe2 - Python API
A deep learning, cross platform ML framework
transformations.py
1 # Copyright (c) 2016-present, Facebook, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 ##############################################################################
15 
16 from __future__ import absolute_import
17 from __future__ import division
18 from __future__ import print_function
19 from __future__ import unicode_literals
20 
22 
23 
24 class Transformer(object):
25  def __init__(self):
26  pass
27 
28  @classmethod
29  def runTransform(cls, transform_name, net):
30  pb = net.Proto().SerializeToString()
31  if C.transform_exists(transform_name):
32  output = C.run_transform(transform_name, pb)
33  elif C.workspace_transform_exists(transform_name):
34  output = C.run_workspace_transform(transform_name, pb)
35  else:
36  raise AttributeError('Transformation {} not found.'.format(transform_name))
37  net.Proto().ParseFromString(output)
38 
39  def __getattr__(self, transform_name):
40  return lambda net : self.runTransform(transform_name, net)
41 
42 
43 def fuseNNPACKConvRelu(net):
44  net.Proto().ParseFromString(
45  C.transform_fuseNNPACKConvRelu(net.Proto().SerializeToString())
46  )
47 
48 
49 def optimizeForIDEEP(net, training_mode = False):
50  net.Proto().ParseFromString(
51  C.transform_optimizeForIDEEP(net.Proto().SerializeToString(), training_mode)
52  )
53 
54 
55 def fuseConvBN(net):
56  net.Proto().ParseFromString(
57  C.transform_fuseConvBN(net.Proto().SerializeToString())
58  )
def runTransform(cls, transform_name, net)