def loop(model, cond_blob, external_blobs, loop_model, cond_model=None): """Loop""" add_while_op( model.net, cond_blob, external_blobs, loop_model.net, cond_model.net if cond_model else None)
def __exit__(self, type, *args): if type is None: assert self._cond_builder, \ 'Condition builder must be specified in While op' _cond_blob = self._cond_builder._cond_blob _cond_net = self._cond_builder._cond_net loop_body = self._children self._reset_children() loop_body_net = NetBuilder.merge_nets( loop_body, self._lexical_scope) if not loop_body_net: loop_body_net = core.Net('empty_loop_body_net') while_net = core.Net(self.name + '/while_net') add_while_op(while_net, _cond_blob, self._lexical_scope, loop_body_net, _cond_net) self._current_net = while_net self._children = [while_net] NetBuilder.__exit__(self, type, *args)