Keras模型到Tensoflow服务器模​​型

时间:2019-01-21 06:18:22

标签: tensorflow keras

访问时出现错误

{ "error": "Generic conv implementation does not support grouped convolutions for now.\n\t [[{{node model_1/conv2d_1/Conv2D}}]]" }

我将模型转换为TF服务器

import tensorflow as tf


tf.keras.backend.set_learning_phase(0)   

model = tf.keras.models.load_model(r'model.h5')
export_path = 'my_image_classifier/1'

with tf.keras.backend.get_session() as sess:
    tf.saved_model.simple_save(
        sess,
        export_path,
        inputs={'input_image': model.input},
        outputs={t.name: t for t in model.outputs})

我该怎么办?我需要服务器上的模型

系统Ubuntu 18.04

TF服务器1.12(Docker)

Keras 1.2.4

2 个答案:

答案 0 :(得分:0)

降级TnesorFlow 1.13.1。

答案 1 :(得分:0)

var TransactionList = new List<int>();
for (int i = 0; i < 59; i++)
{
    TransactionList.Add(0);
}

// var index = new Random().Next(0, 59);
// Below will work for dynamic length of list.
var index = new Random().Next(0, TransactionList.Count);
TransactionList[index] = 5;

主要是要包括

from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import tag_constants
from tensorflow.python.saved_model.signature_def_utils_impl import predict_signature_def
from tensorflow.keras import backend as K
import tensorflow as tf


export_path = 'model'
sess = tf.Session()

K.set_session(sess)
K.set_learning_phase(0)

json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()

model = tf.keras.models.model_from_json(loaded_model_json)
model.load_weights('01.h5')

model.summary()

builder = saved_model_builder.SavedModelBuilder(export_path)

signature = predict_signature_def(inputs={'input_image': model.get_layer(name='the_input').input},
                                  outputs={'out': model.get_layer(name='the_output').output})

with K.get_session() as sess:
    builder.add_meta_graph_and_variables(sess=sess,
                                         tags=[tag_constants.SERVING],
                                         signature_def_map={'predict': signature},
                                         strip_default_attrs=True)
    builder.save()