(self, param_name, shape, initializer, optimizer=None,
ps_param=None, regularizer=None)
| 304 | raise ValueError("optim should be either None, NoOptim, or an instance of Optimizer, Got {} ".format(optim)) |
| 305 | |
| 306 | def create_param(self, param_name, shape, initializer, optimizer=None, |
| 307 | ps_param=None, regularizer=None): |
| 308 | if isinstance(param_name, core.BlobReference): |
| 309 | param_name = str(param_name) |
| 310 | elif isinstance(param_name, str): |
| 311 | # Parameter name will be equal to current Namescope that got |
| 312 | # resolved with the respect of parameter sharing of the scopes. |
| 313 | param_name = parameter_sharing_context.get_parameter_name( |
| 314 | param_name) |
| 315 | else: |
| 316 | raise ValueError("Unsupported type for param_name") |
| 317 | |
| 318 | param_blob = core.BlobReference(param_name) |
| 319 | |
| 320 | if len(initializer) == 1: |
| 321 | init_op_args = {} |
| 322 | else: |
| 323 | assert len(initializer) == 2 |
| 324 | init_op_args = copy.deepcopy(initializer[1]) |
| 325 | if shape is not None: |
| 326 | assert 'shape' not in init_op_args |
| 327 | init_op_args.update({'shape': shape}) |
| 328 | |
| 329 | initializer_op = None |
| 330 | if self._initialize_params: |
| 331 | initializer_op = core.CreateOperator( |
| 332 | initializer[0], |
| 333 | [], |
| 334 | param_blob, |
| 335 | **init_op_args |
| 336 | ) |
| 337 | |
| 338 | param = layers.LayerParameter( |
| 339 | parameter=param_blob, |
| 340 | initializer=initializer_op, |
| 341 | optimizer=optimizer, |
| 342 | ps_param=ps_param, |
| 343 | regularizer=regularizer |
| 344 | ) |
| 345 | |
| 346 | self._validate_param_shape(param_name, shape) |
| 347 | |
| 348 | self._validate_param_optim(param_name, optimizer) |
| 349 | |
| 350 | self._param_to_shape[param_name] = shape |
| 351 | |
| 352 | return param |
| 353 | |
| 354 | def next_layer_name(self, prefix): |
| 355 | base_name = core.ScopedName(prefix) |
nothing calls this directly
no test coverage detected