我正在使用Google AutoML Vision导出的分类模型,因此我只有saved_model.pb
,没有变量,检查点等。
我想将此模型图加载到本地TensorFlow安装中,用于推理并继续训练更多图片。
主要问题:
-
该计划是否可行,即使用不带变量,检查点等的单个
saved_model.pb
并使用新数据训练结果图? -
如果是:如何将图像编码为字符串的输入形状为
(?,)
? -
理想情况下,展望未来:培训部分需要考虑什么重要事项?
有关代码的背景信息:
-
要读取图像,我使用与使用Docker容器进行推理时使用的相同方法,因此使用base64编码的图像。
-
要加载图形,我通过
saved_model_cli show --dir input/model
的CLI(serve
)检查了图形需要设置的标记。 -
要获取输入张量名称,我使用
graph.get_operations()
,它为 image_bytes 提供Placeholder:0
,为 key提供Placeholder:1_0
。 em>(只是一个任意字符串标识图像)。两者都具有维度dim -1
import tensorflow as tf
import numpy as np
import base64
path_img = "input/testimage.jpg"
path_mdl = "input/model"
# input to network expected to be base64 encoded image
with io.open(path_img,'rb') as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
# reshaping to (1,) as the expecte dimension is (?,)
feed_dict_option1 = {
"Placeholder:0": { np.array(str(encoded_image)).reshape(1,) },"Placeholder_1:0" : "image_key"
}
# reshaping to (1,1) as the expecte dimension is (?,)
feed_dict_option2 = {
"Placeholder:0": np.array(str(encoded_image)).reshape(1,1),"Placeholder_1:0" : "image_key"
}
with tf.Session(graph=tf.Graph()) as sess:
tf.saved_model.loader.load(sess,["serve"],path_mdl)
graph = tf.get_default_graph()
sess.run('scores:0',feed_dict=feed_dict_option1)
sess.run('scores:0',feed_dict=feed_dict_option2)
输出:
# for input reshaped to (1,)
ValueError: Cannot feed value of shape (1,) for Tensor 'Placeholder:0',which has shape '(?,)'
# for input reshaped to (1,1)
ValueError: Cannot feed value of shape (1,1) for Tensor 'Placeholder:0',)'
如何获得(?,)
的输入形状?
非常感谢。