如何将张量流模型转换为protobuf模型?

时间:2020-05-19 15:06:40

标签: python tensorflow protocol-buffers

我试图将我的张量流模型转换为protobuf,但是我不了解如何分配输入和输出张量。如何将其转换为protobuf格式,谁能告诉我如何分配模型的输入张量?

with tf.Session(graph=cnn_graph) as sess:
# load model
loader = tf.train.import_meta_graph(model_save_path + '.meta')
loader.restore(sess, model_save_path)

# obtain tensors
x = cnn_graph.get_tensor_by_name('x:0')
y = cnn_graph.get_tensor_by_name('y:0')
keep_prob = cnn_graph.get_tensor_by_name('keep_prob:0')
logits = cnn_graph.get_tensor_by_name('logits:0')

# use model to predict from test features
# loop over test batches
for batch_index in range(test_batches.shape[0]):
    test_features_batch, test_ids_batch = read_batch(test_batches[batch_index])
    predictions = sess.run(tf.nn.softmax(logits), feed_dict={
        x: test_features_batch,
        keep_prob: 1.
    })

    for test_index in range(len(test_ids_batch)):
        # save predictions to file
        prediction_file.write(test_ids_batch[test_index] + ',' + str(predictions[test_index,1]) + 
    '\n')
        # print out predictions
        print('ID: ' + test_ids_batch[test_index] + ', Cancer probability: ' + 
    str(predictions[test_index,1]))

    prediction_file.close()

0 个答案:

没有答案