Returns predictions for a single batch of samples. Arguments: x: Input data. It could be: - A Numpy array (or array-like), or a list of arrays (in case the model has multiple inputs). - A TensorFlow tensor, or a list of tensors (in case the mo
(self, x)
| 1112 | return outputs |
| 1113 | |
| 1114 | def predict_on_batch(self, x): |
| 1115 | """Returns predictions for a single batch of samples. |
| 1116 | |
| 1117 | Arguments: |
| 1118 | x: Input data. It could be: |
| 1119 | - A Numpy array (or array-like), or a list of arrays |
| 1120 | (in case the model has multiple inputs). |
| 1121 | - A TensorFlow tensor, or a list of tensors |
| 1122 | (in case the model has multiple inputs). |
| 1123 | - A `tf.data` dataset. |
| 1124 | |
| 1125 | Returns: |
| 1126 | Numpy array(s) of predictions. |
| 1127 | |
| 1128 | Raises: |
| 1129 | ValueError: In case of mismatch between given number of inputs and |
| 1130 | expectations of the model. |
| 1131 | """ |
| 1132 | self._check_call_args('predict_on_batch') |
| 1133 | if self._experimental_run_tf_function: |
| 1134 | return training_v2_utils.predict_on_batch(self, x) |
| 1135 | |
| 1136 | if (self._distribution_strategy and |
| 1137 | distribution_strategy_context.in_cross_replica_context()): |
| 1138 | raise NotImplementedError( |
| 1139 | '`predict_on_batch` is not supported for models distributed with' |
| 1140 | ' tf.distribute.Strategy.') |
| 1141 | # Validate and standardize user data. |
| 1142 | inputs, _, _ = self._standardize_user_data( |
| 1143 | x, extract_tensors_from_dataset=True) |
| 1144 | # If `self._distribution_strategy` is True, then we are in a replica context |
| 1145 | # at this point. |
| 1146 | if self.run_eagerly or self._distribution_strategy: |
| 1147 | inputs = training_utils.cast_if_floating_dtype(inputs) |
| 1148 | if isinstance(inputs, collections_abc.Sequence): |
| 1149 | # Unwrap lists with only one input, as we do when training on batch |
| 1150 | if len(inputs) == 1: |
| 1151 | inputs = inputs[0] |
| 1152 | |
| 1153 | return self(inputs) # pylint: disable=not-callable |
| 1154 | |
| 1155 | self._make_predict_function() |
| 1156 | outputs = self.predict_function(inputs) |
| 1157 | |
| 1158 | if len(outputs) == 1: |
| 1159 | return outputs[0] |
| 1160 | return outputs |
| 1161 | |
| 1162 | def fit_generator(self, |
| 1163 | generator, |