|
1 | 1 | package com.google.showcase.v1beta1.it; |
2 | 2 |
|
| 3 | +import static com.google.common.truth.Truth.assertThat; |
| 4 | + |
3 | 5 | import org.junit.jupiter.api.Test; |
4 | 6 | import org.tensorflow.Graph; |
5 | 7 | import org.tensorflow.Session; |
|
9 | 11 | import org.tensorflow.proto.GraphDef; |
10 | 12 | import org.tensorflow.types.TInt32; |
11 | 13 |
|
12 | | -import static com.google.common.truth.Truth.assertThat; |
13 | | -// Tensorflow depends on protobuf 3.x gen code and runtime, we test it in showcase module to prove that it works with |
| 14 | +// Tensorflow depends on protobuf 3.x gen code and runtime, we test it in showcase module to prove |
| 15 | +// that it works with |
14 | 16 | // protobuf 4.33+ gen code and runtime that comes with client libraries. |
15 | 17 | public class ITProtobuf3Compatibility { |
16 | 18 |
|
17 | | - @Test |
18 | | - void testTensorflow_helloWorldExample() { |
19 | | - try (Graph graph = new Graph()) { |
20 | | - // Hello world example for "10 + 32" operation. |
21 | | - Ops tf = Ops.create(graph); |
| 19 | + @Test |
| 20 | + void testTensorflow_helloWorldExample() { |
| 21 | + try (Graph graph = new Graph()) { |
| 22 | + // Hello world example for "10 + 32" operation. |
| 23 | + Ops tf = Ops.create(graph); |
22 | 24 |
|
23 | | - Constant<TInt32> expectedValue1 = tf.constant(10); |
24 | | - Constant<TInt32> expectedValue2 = tf.constant(32); |
| 25 | + Constant<TInt32> expectedValue1 = tf.constant(10); |
| 26 | + Constant<TInt32> expectedValue2 = tf.constant(32); |
25 | 27 |
|
26 | | - Add<TInt32> sum = tf.math.add(expectedValue1, expectedValue2); |
| 28 | + Add<TInt32> sum = tf.math.add(expectedValue1, expectedValue2); |
27 | 29 |
|
28 | | - try (Session s = new Session(graph)) { |
29 | | - try (TInt32 result = (TInt32) s.runner().fetch(sum).run().get(0)) { |
30 | | - System.out.println("10 + 32 = " + result.getInt()); |
31 | | - } |
32 | | - } |
| 30 | + try (Session s = new Session(graph)) { |
| 31 | + try (TInt32 result = (TInt32) s.runner().fetch(sum).run().get(0)) { |
| 32 | + System.out.println("10 + 32 = " + result.getInt()); |
| 33 | + } |
| 34 | + } |
33 | 35 |
|
34 | | - //GraphDef is a protobuf gen code. |
35 | | - GraphDef graphDef = graph.toGraphDef(); |
| 36 | + // GraphDef is a protobuf gen code. |
| 37 | + GraphDef graphDef = graph.toGraphDef(); |
36 | 38 |
|
37 | | - //Inspect the protobuf gen code |
38 | | - Integer actual1 = graphDef.getNode(0).getAttrOrThrow("value").getTensor().getIntValList().get(0); |
39 | | - Integer actual2 = graphDef.getNode(1).getAttrOrThrow("value").getTensor().getIntValList().get(0); |
| 39 | + // Inspect the protobuf gen code |
| 40 | + Integer actual1 = |
| 41 | + graphDef.getNode(0).getAttrOrThrow("value").getTensor().getIntValList().get(0); |
| 42 | + Integer actual2 = |
| 43 | + graphDef.getNode(1).getAttrOrThrow("value").getTensor().getIntValList().get(0); |
40 | 44 |
|
41 | | - assertThat(actual1).isEqualTo(expectedValue1); |
42 | | - assertThat(actual2).isEqualTo(expectedValue2); |
43 | | - } |
| 45 | + assertThat(actual1).isEqualTo(expectedValue1); |
| 46 | + assertThat(actual2).isEqualTo(expectedValue2); |
44 | 47 | } |
| 48 | + } |
45 | 49 | } |
0 commit comments