Args: get_model (input1, input2, ... -> keras.Model): A function which takes tensors, builds and returns a Keras model. It will be part of the tower function. input_signature ([tf.TensorSpec]): required. The signature for inputs.
(self, get_model, input_signature=None, target_signature=None,
input=None, trainer=None)
| 224 | |
| 225 | class KerasModel(object): |
| 226 | def __init__(self, get_model, input_signature=None, target_signature=None, |
| 227 | input=None, trainer=None): |
| 228 | """ |
| 229 | Args: |
| 230 | get_model (input1, input2, ... -> keras.Model): |
| 231 | A function which takes tensors, builds and returns a Keras model. |
| 232 | It will be part of the tower function. |
| 233 | input_signature ([tf.TensorSpec]): required. The signature for inputs. |
| 234 | target_signature ([tf.TensorSpec]): required. The signature for the targets tensors. |
| 235 | input (InputSource | DataFlow): the InputSource or DataFlow where the input data comes from. |
| 236 | trainer (Trainer): the default will check the number of available GPUs and use them all. |
| 237 | """ |
| 238 | self.get_model = get_model |
| 239 | assert callable(get_model), get_model |
| 240 | self.input_signature = input_signature |
| 241 | self.target_signature = target_signature |
| 242 | if trainer is None: |
| 243 | nr_gpu = get_nr_gpu() |
| 244 | if nr_gpu <= 1: |
| 245 | trainer = SimpleTrainer() |
| 246 | else: |
| 247 | # the default multi-gpu trainer |
| 248 | trainer = SyncMultiGPUTrainerParameterServer(nr_gpu) |
| 249 | assert isinstance(trainer, Trainer), trainer |
| 250 | assert not isinstance(trainer, DistributedTrainerBase) |
| 251 | |
| 252 | assert input is not None, "Argument 'input' is required!" |
| 253 | self.input = apply_default_prefetch(input, trainer) |
| 254 | self.trainer = trainer |
| 255 | |
| 256 | def compile(self, optimizer, loss, metrics=None): |
| 257 | """ |
nothing calls this directly
no test coverage detected