栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

AutoML Vision Edge中的saved_model无法正确加载

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

AutoML Vision Edge中的saved_model无法正确加载

我已经

saved_model.pb
在docker容器之外进行了工作(用于对象检测,而不是分类-但它们应该是相似的,更改的输出以及输入
tf1.14
),这是如何做的:

张量流1.14.0:

图像编码为字节

import cv2import tensorflow as tfcv2.imread(filepath)flag, bts = cv.imenpre('.jpg', img)inp = [bts[:,0].tobytes()]with tf.Session(graph=tf.Graph()) as sess:    tf.saved_model.loader.load(sess, ['serve'], 'directory_of_saved_model')    graph = tf.get_default_graph()    out = sess.run([sess.graph.get_tensor_by_name('num_detections:0'), sess.graph.get_tensor_by_name('detection_scores:0'), sess.graph.get_tensor_by_name('detection_boxes:0'), sess.graph.get_tensor_by_name('detection_classes:0')],feed_dict={'enpred_image_string_tensor:0': inp})

图像作为numpy数组

import cv2import tensorflow as tfimport numpy as npwith tf.Session(graph=tf.Graph()) as sess:    tf.saved_model.loader.load(sess, ['serve'], 'directory_of_saved_model')    graph = tf.get_default_graph()    # Read and preprocess an image.    img = cv2.imread(filepath)    # Run the model    out = sess.run([sess.graph.get_tensor_by_name('num_detections:0'),         sess.graph.get_tensor_by_name('detection_scores:0'),         sess.graph.get_tensor_by_name('detection_boxes:0'),         sess.graph.get_tensor_by_name('detection_classes:0')],        feed_dict={'map/TensorArrayStack/TensorArrayGatherV3:0': img[np.newaxis, :, :, :]})

我使用netron查找我的输入。

张量流2.0:

import cv2import tensorflow as tfimg = cv2.imread('path_to_image_file')flag, bts = cv2.imenpre('.jpg', img)inp = [bts[:,0].tobytes()]loaded = tf.saved_model.load(export_dir='directory_of_saved_model')infer = loaded.signatures["serving_default"]out = infer(key=tf.constant('something_unique'), image_bytes=tf.constant(inp))


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/419941.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号