This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tensor : model/layer_with_weights-0/bias/.OPTIMIZER_SLOT/opt/m/.ATTRIBUTES/VARIABLE_VALUE (30,) | |
| [ 3.4107354e-05 -6.1855838e-04 -1.6536651e-06 1.6930330e-06 | |
| -9.1597438e-05 -3.8669934e-04 5.6557164e-05 7.1755665e-08 | |
| -1.2517045e-04 -1.0449246e-03 5.9954262e-05 7.3613039e-05 | |
| 6.6272205e-06 -5.7156640e-04 5.4908687e-06 -7.3699164e-05 | |
| -8.7973615e-04 -3.6661630e-04 5.2946081e-05 -5.7122961e-04 | |
| -8.7792240e-04 -4.1600107e-04 -1.2562575e-03 -2.4318745e-06 | |
| 7.0880642e-06 9.7999236e-06 -6.5629813e-04 1.1121790e-05 | |
| -1.3819840e-03 6.7142719e-06] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def train_predict_serve(model_dir): | |
| tf.compat.v1.reset_default_graph() | |
| session = tf.compat.v1.Session() | |
| tf.compat.v1.saved_model.loader.load(session, tags=[tf.saved_model.SERVING], export_dir=model_dir) | |
| graph = session.graph | |
| operations=graph.get_operations() | |
| input_X = graph.get_tensor_by_name('my_train_X:0') | |
| input_y = graph.get_tensor_by_name('my_train_y:0') | |
| output_loss = graph.get_tensor_by_name('StatefulPartitionedCall_1:0') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| input_X = graph.get_tensor_by_name('my_train_X:0') | |
| input_y = graph.get_tensor_by_name('my_train_y:0') | |
| output_1 = graph.get_tensor_by_name('StatefulPartitionedCall_1:0') | |
| output_2 = graph.get_tensor_by_name('StatefulPartitionedCall_1:1') | |
| out_val_1, out_val_2 = session.run([output_1, output_2], | |
| feed_dict={input_X: X_train[0:1], input_y: y_train[0:1]}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TrainAndServeSavedModel { | |
| public static void main(String[] args) throws Exception { | |
| // args[0]: saved model directory | |
| SavedModelBundle savedModel = SavedModelBundle.load(args[0], "serve"); | |
| Map<String, SignatureDef> signatureMap = savedModel.metaGraphDef().getSignatureDefMap(); | |
| Tensor<TFloat32> inputTensor = TFloat32.tensorOf(StdArrays.ndCopyOf(new float[][] { { 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f } })); | |
| Tensor<TFloat32> labelTensor = TFloat32.tensorOf(StdArrays.ndCopyOf(new float[] { 1.0f })); | |
OlderNewer