| 44 | }; |
| 45 | |
| 46 | TEST_F(RemapperTest, FusedBatchNorm) { |
| 47 | tensorflow::Scope s = tensorflow::Scope::NewRootScope(); |
| 48 | Output dflt = ops::Const(s.WithOpName("dflt"), {3.14f, 2.7f}, {2, 1, 1, 1}); |
| 49 | Output x = ops::PlaceholderWithDefault(s.WithOpName("x"), dflt, {2, 1, 1, 1}); |
| 50 | Output scale = ops::Const(s.WithOpName("scale"), {0.3f}, {1}); |
| 51 | Output offset = ops::Const(s.WithOpName("offset"), {0.123f}, {1}); |
| 52 | Output mean = ops::Const(s.WithOpName("mean"), {7.3f}, {1}); |
| 53 | Output variance = ops::Const(s.WithOpName("variance"), {0.57f}, {1}); |
| 54 | ops::FusedBatchNorm::Attrs attr; |
| 55 | attr = attr.IsTraining(false); |
| 56 | ops::FusedBatchNorm bn(s.WithOpName("batch_norm"), x, scale, offset, mean, |
| 57 | variance, attr); |
| 58 | |
| 59 | GrapplerItem item; |
| 60 | TF_ASSERT_OK(s.ToGraphDef(&item.graph)); |
| 61 | item.fetch = {"batch_norm"}; |
| 62 | |
| 63 | auto tensors_expected = EvaluateNodes(item.graph, item.fetch); |
| 64 | ASSERT_EQ(tensors_expected.size(), 1); |
| 65 | |
| 66 | Remapper optimizer(RewriterConfig::ON); |
| 67 | GraphDef output; |
| 68 | TF_ASSERT_OK(optimizer.Optimize(nullptr, item, &output)); |
| 69 | |
| 70 | auto tensors = EvaluateNodes(output, item.fetch); |
| 71 | ASSERT_EQ(tensors.size(), 1); |
| 72 | test::ExpectTensorNear<float>(tensors[0], tensors_expected[0], 1e-6); |
| 73 | } |
| 74 | |
| 75 | // Fails at optimizer.Optimize() call with error |
| 76 | // Which is: Invalid argument: Mutation::Apply error: multiple nodes with the name: 'batch_norm/NCHWShapedOffset' exists in Mutation. |
nothing calls this directly
no test coverage detected