Instantiate a model. Args: layers: a list of layers to be added to the model. *args: Model's args **kwargs: Model's keyword args, at most one of input_tensor -> the input tensor required for ragged/sparse input.
(self, layers, *args, **kwargs)
| 442 | """A Keras subclass model.""" |
| 443 | |
| 444 | def __init__(self, layers, *args, **kwargs): |
| 445 | """Instantiate a model. |
| 446 | |
| 447 | Args: |
| 448 | layers: a list of layers to be added to the model. |
| 449 | *args: Model's args |
| 450 | **kwargs: Model's keyword args, at most one of |
| 451 | input_tensor -> the input tensor required for ragged/sparse input. |
| 452 | """ |
| 453 | |
| 454 | inputs = kwargs.pop('input_tensor', None) |
| 455 | super(_SubclassModel, self).__init__(*args, **kwargs) |
| 456 | # Note that clone and build doesn't support lists of layers in subclassed |
| 457 | # models. Adding each layer directly here. |
| 458 | for i, layer in enumerate(layers): |
| 459 | setattr(self, self._layer_name_for_i(i), layer) |
| 460 | |
| 461 | self.num_layers = len(layers) |
| 462 | |
| 463 | if inputs is not None: |
| 464 | self._set_inputs(inputs) |
| 465 | |
| 466 | def _layer_name_for_i(self, i): |
| 467 | return 'layer{}'.format(i) |