Caffe2 - Python API
A deep learning, cross platform ML framework
control_ops.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 ## @package control_ops
17 # Module caffe2.python.helpers.control_ops
18 from __future__ import absolute_import
19 from __future__ import division
20 from __future__ import print_function
21 from __future__ import unicode_literals
22 
23 from caffe2.python.control_ops_util import add_if_op, add_while_op
24 
25 
26 def cond(model, cond_blob, external_blobs, then_model, else_model=None):
27  """Condition"""
28  add_if_op(
29  model.net,
30  cond_blob,
31  external_blobs,
32  then_model.net,
33  else_model.net if else_model else None)
34 
35 
36 def loop(model, cond_blob, external_blobs, loop_model, cond_model=None):
37  """Loop"""
38  add_while_op(
39  model.net,
40  cond_blob,
41  external_blobs,
42  loop_model.net,
43  cond_model.net if cond_model else None)