(self)
| 553 | |
| 554 | @test_util.run_deprecated_v1 |
| 555 | def testGetUpdateFor(self): |
| 556 | |
| 557 | class MyLayer(base_layers.Layer): |
| 558 | |
| 559 | def build(self, input_shape): |
| 560 | self.a = self.add_variable('a', |
| 561 | (), |
| 562 | dtypes.float32, |
| 563 | trainable=False) |
| 564 | self.b = self.add_variable('b', |
| 565 | (), |
| 566 | dtypes.float32, |
| 567 | trainable=False) |
| 568 | self.add_update(state_ops.assign_add(self.a, 1., name='b_update')) |
| 569 | self.built = True |
| 570 | |
| 571 | def call(self, inputs): |
| 572 | self.add_update(state_ops.assign_add(self.a, inputs, name='a_update'), |
| 573 | inputs=True) |
| 574 | return inputs + 1 |
| 575 | |
| 576 | layer = MyLayer() |
| 577 | inputs = array_ops.placeholder(dtypes.float32, (), 'inputs') |
| 578 | intermediate_inputs = inputs + 1 |
| 579 | outputs = layer.apply(intermediate_inputs) |
| 580 | |
| 581 | self.assertEqual(len(layer.updates), 2) |
| 582 | self.assertEqual(len(layer.get_updates_for(None)), 1) |
| 583 | self.assertEqual(len(layer.get_updates_for([inputs])), 1) |
| 584 | self.assertEqual(len(layer.get_updates_for([intermediate_inputs])), 1) |
| 585 | self.assertEqual(len(layer.get_updates_for([outputs])), 0) |
| 586 | |
| 587 | # Call same layer on new input, creating one more conditional update |
| 588 | inputs = array_ops.placeholder(dtypes.float32, (), 'inputs') |
| 589 | intermediate_inputs = inputs + 1 |
| 590 | outputs = layer.apply(intermediate_inputs) |
| 591 | |
| 592 | self.assertEqual(len(layer.updates), 3) |
| 593 | self.assertEqual(len(layer.get_updates_for(None)), 1) |
| 594 | # Check that we are successfully filtering out irrelevant updates |
| 595 | self.assertEqual(len(layer.get_updates_for([inputs])), 1) |
| 596 | self.assertEqual(len(layer.get_updates_for([intermediate_inputs])), 1) |
| 597 | self.assertEqual(len(layer.get_updates_for([outputs])), 0) |
| 598 | |
| 599 | @test_util.run_deprecated_v1 |
| 600 | def testGetLossesFor(self): |
nothing calls this directly
no test coverage detected