Adds layer trainig or initialization operators to the passed in net. init_net can be None and can be called independently from add_init_params
(self, net, init_net=None, context=InstantiationContext.TRAINING)
| 422 | return self.model.net.NextScopedBlob(name) |
| 423 | |
| 424 | def add_operators(self, net, init_net=None, context=InstantiationContext.TRAINING): |
| 425 | """ |
| 426 | Adds layer trainig or initialization operators to the passed in net. |
| 427 | init_net can be None and can be called independently from add_init_params |
| 428 | """ |
| 429 | # Namescope below should warranty that all intermediate blobs will be |
| 430 | # assiciated with the layer that produces them |
| 431 | with scope.NameScope(self.name): |
| 432 | if context not in { |
| 433 | InstantiationContext.PREDICTION, |
| 434 | InstantiationContext.EVAL, |
| 435 | InstantiationContext.ACCUMULATE_PRED, |
| 436 | }: |
| 437 | assert init_net, "Only prediction and eval context don't need init_net" |
| 438 | if init_net: |
| 439 | self.add_init_params(init_net) |
| 440 | if context == InstantiationContext.TRAINING: |
| 441 | self.add_train_ops(net) |
| 442 | elif context == InstantiationContext.EVAL: |
| 443 | self.add_eval_ops(net) |
| 444 | elif context == InstantiationContext.ACCUMULATE_PRED: |
| 445 | self.add_ops_to_accumulate_pred(net) |
| 446 | else: |
| 447 | self.add_ops(net) |
| 448 | |
| 449 | if ( |
| 450 | context in {InstantiationContext.TRAINING, InstantiationContext.EVAL} |
| 451 | and self._export_params_for_metrics |
| 452 | ): |
| 453 | self.add_param_copy_operators(net) |
| 454 | |
| 455 | def add_ops(self, net): |
| 456 | # Predict layer implementation. |