Adds layer initialization operators to passed net.
(self, init_net)
| 367 | return {} |
| 368 | |
| 369 | def add_init_params(self, init_net): |
| 370 | """ |
| 371 | Adds layer initialization operators to passed net. |
| 372 | """ |
| 373 | for param in self.params: |
| 374 | # TODO(amalevich): Either return back to lambdas, that add |
| 375 | # all params (looks a bit safer and breaking less |
| 376 | # abstractions) or extend Net interface to this type of |
| 377 | # operations better |
| 378 | # TODO(xlwang) init_net._net.op has type google.protobuf.\ |
| 379 | # internal.containers.RepeatedCompositeFieldContainer, but |
| 380 | # the version of protobuf in fbcode does not support append |
| 381 | # so extend is used |
| 382 | init_op = param.initializer |
| 383 | current_device_scope = scope.CurrentDeviceScope() |
| 384 | if not init_op: |
| 385 | continue |
| 386 | |
| 387 | if not init_op.HasField("device_option") and current_device_scope: |
| 388 | init_op = caffe2_pb2.OperatorDef() |
| 389 | init_op.CopyFrom(param.initializer) |
| 390 | init_op.device_option.CopyFrom(current_device_scope) |
| 391 | |
| 392 | # do not add duplicated init ops |
| 393 | if any( |
| 394 | utils.OpAlmostEqual(op, init_op, "debug_info") |
| 395 | for op in init_net._net.op |
| 396 | ): |
| 397 | continue |
| 398 | |
| 399 | init_net._net.op.extend([init_op]) |
| 400 | |
| 401 | def create_param( |
| 402 | self, param_name, shape, initializer, optimizer, ps_param=None, regularizer=None |
no test coverage detected