Я пытаюсь конвертировать мой pb в tflite, используя этот код. Я получил код от github ( ImageCaptioning ). Авторы использовали этот код для преобразования своей модели, и я смог создать модель pb, но столкнулся с некоторыми проблемами при попытке преобразовать модель pb в tflite.
import tensorflow as tf
from tensorflow.python.platform import gfile
import cv2
import numpy as np
def main():
sess = tf.Session()
GRAPH_LOCATION = 'C:/Users/User/Documents/models-master/research/im2txt/im2txt/data/output_graph.pb'
VOCAB_FILE = 'C:/Users/User/Documents/models-master/research/im2txt/Pretrained-Show-and-Tell-model-master/word_counts.txt'
IMAGE_FILE = 'C:/Users/User/Documents/models-master/research/im2txt/g3doc/COCO_val2014_000000224477.jpg'
# Read model
with gfile.FastGFile(GRAPH_LOCATION, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
sess.graph.as_default()
tf.import_graph_def(graph_def)
with tf.gfile.GFile(IMAGE_FILE, "rb") as f:
encoded_image = f.read()
input_names = ['import/image_feed:0', 'import/input_feed:0', 'import/lstm/state_feed:0']
output_names = ['import/softmax:0', 'import/lstm/state:0', 'import/lstm/initial_state:0']
g = tf.get_default_graph()
input_tensors = [g.get_tensor_by_name(x) for x in input_names]
output_tensors = [g.get_tensor_by_name(x) for x in output_names]
converter = tf.lite.TFLiteConverter.from_session(sess, input_tensors, output_tensors)
model = converter.convert()
fid = open("C:/Users/User/Documents/models-master/research/im2txt/im2txt/data/converted_model.tflite", "wb")
fid.write(model)
fid.close()
if __name__ == '__main__':
main()
, но я получаю это ошибка:
"'{0}'.".format(_get_tensor_name(tensor)))
ValueError: Provide an input shape for input array 'import/image_feed'.
Я новичок в tfLite и не могу найти проблему, связанную с кодом.