| 2136 | self._set_trainable_state(current_trainable_state) |
| 2137 | |
| 2138 | def _make_test_function(self): |
| 2139 | has_recompiled = self._recompile_weights_loss_and_weighted_metrics() |
| 2140 | # If we have re-compiled the loss/weighted metric sub-graphs then create |
| 2141 | # test function even if one exists already. This is because |
| 2142 | # `_feed_sample_weights` list has been updated on re-copmpile. |
| 2143 | if getattr(self, 'test_function', None) is None or has_recompiled: |
| 2144 | inputs = (self._feed_inputs + |
| 2145 | self._feed_targets + |
| 2146 | self._feed_sample_weights) |
| 2147 | |
| 2148 | with K.get_graph().as_default(): |
| 2149 | metrics = self._get_training_eval_metrics() |
| 2150 | metrics_tensors = [ |
| 2151 | m._call_result for m in metrics if hasattr(m, '_call_result') # pylint: disable=protected-access |
| 2152 | ] |
| 2153 | |
| 2154 | with K.name_scope('evaluation'): |
| 2155 | updates = self.state_updates |
| 2156 | # Return loss and metrics, no gradient updates. |
| 2157 | # Does update the network states. |
| 2158 | fn = K.function( |
| 2159 | inputs, [self.total_loss] + metrics_tensors, |
| 2160 | updates=updates, |
| 2161 | name='test_function', |
| 2162 | **self._function_kwargs) |
| 2163 | setattr(self, 'test_function', fn) |
| 2164 | |
| 2165 | def _make_predict_function(self): |
| 2166 | if not hasattr(self, 'predict_function'): |