|
31 | 31 | model.fit(x_train, y_train, epochs=1) |
32 | 32 |
|
33 | 33 | # convert output type through softmax so that it can be interpreted as probability |
34 | | -probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()]) |
35 | | - |
36 | | -# convert keras model to TF2 function to get a computation graph |
37 | | -x = tf.TensorSpec((None, 28, 28), tf.float32) |
38 | | -predict = tf.function(lambda x: probability_model(x)).get_concrete_function(x=x) |
| 34 | +probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax(name="output")]) |
39 | 35 |
|
40 | 36 | # dump expected values to compare Rust's outputs |
41 | 37 | with open("examples/mnist_savedmodel/expected_values.txt", "w") as f: |
42 | | - values = predict(x_test[:1, :, :]).numpy() |
| 38 | + values = probability_model(x_test[:1, :, :])[0].numpy() |
43 | 39 | print(*values, sep=", ", file=f) |
44 | 40 |
|
45 | 41 | directory = "examples/mnist_savedmodel" |
46 | | -signatures = {"predict": predict} |
47 | | -tf.saved_model.save(model, directory, signatures=signatures) |
| 42 | +tf.saved_model.save(probability_model, directory) |
48 | 43 |
|
49 | 44 | # export graph info to TensorBoard |
50 | 45 | logdir = "logs/mnist_savedmodel" |
51 | 46 | writer = tf.summary.create_file_writer(logdir) |
| 47 | +tf.summary.trace_on() |
| 48 | +values = probability_model(x_test[:1, :, :]) |
52 | 49 | with writer.as_default(): |
53 | | - tf.summary.graph(predict.graph) |
| 50 | + tf.summary.trace_export("Default", step=0) |
0 commit comments