第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AutoML Vision Edge 中的 saved_model 未正確加載

AutoML Vision Edge 中的 saved_model 未正確加載

瀟湘沐 2022-06-28 11:04:41
在以 TFLite 格式導出模型時,我一直在使用 AutoML Vision Edge 完成一些圖像分類任務,并取得了很好的效果。但是,我只是嘗試導出 saved_model.pb 文件并使用 Tensorflow 2.0 運行它,似乎遇到了一些問題。代碼片段:import numpy as npimport tensorflow as tfimport cv2from tensorflow import kerasmy_model = tf.keras.models.load_model('saved_model')print(my_model)print(my_model.summary())'saved_model' 是包含我下載的 saved_model.pb 文件的目錄。這是我所看到的:2019-10-18 23:29:08.801647: I tensorflow/core/platform/cpu_feature_guard.cc:142] 您的 CPU 支持未編譯此 TensorFlow 二進制文件以使用的指令:AVX2 FMA 2019-10-18 23:29:08.829017 :我 tensorflow/compiler/xla/service/service.cc:168] XLA 服務 0x7ffc2d717510 在平臺主機上執(zhí)行計算。設備:2019-10-18 23:29:08.829038:I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor 設備(0):主機,默認版本回溯(最后一次調(diào)用):文件“classify_in_out_tf2. py",第 81 行,在 print(my_model.summary()) AttributeError: 'AutoTrackable' 對象沒有屬性 'summary'我不確定這是我如何導出模型的問題,還是我的代碼加載模型的問題,或者這些模型是否與 Tensorflow 2.0 或某種組合不兼容。任何幫助將不勝感激!
查看完整描述

1 回答

?
慕娘9325324

TA貢獻1783條經(jīng)驗 獲得超4個贊

我已經(jīng)saved_model.pb在 docker 容器之外工作了(用于對象檢測,而不是分類 - 但它們應該是相似的,更改輸出,也許更改輸入tf 1.14),方法如下:


張量流 1.14.0:

圖像編碼為字節(jié)

import cv2

import tensorflow as tf

cv2.imread(filepath)

flag, bts = cv.imencode('.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={'encoded_image_string_tensor:0': inp})

圖像為 numpy 數(shù)組

import cv2

import tensorflow as tf

import numpy as np

with 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 cv2

import tensorflow as tf

img = cv2.imread('path_to_image_file')

flag, bts = cv2.imencode('.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))


查看完整回答
反對 回復 2022-06-28
  • 1 回答
  • 0 關(guān)注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號