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

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

如何在ml引擎中構建用于對象檢測預測的uint8 numpy數(shù)組輸入張量

如何在ml引擎中構建用于對象檢測預測的uint8 numpy數(shù)組輸入張量

慕工程0101907 2021-07-15 14:02:39
我想根據(jù) Google ML 引擎中現(xiàn)有的模型進行在線對象檢測預測(或推理)。但我無法構建 json 請求。模型是來自TF模型動物園的faster_rcnn_inception_resnet_v2_atrous_coco_2017_11_08。輸入是圖像輸出類,bb,分數(shù)等...所需的輸入是(來自 saved_model_cli show )inputs['inputs'] tensor_info:dtype: DT_UINT8shape: (-1, -1, -1, 3)name: image_tensor:0因為它需要一個 uint8 數(shù)組,所以我將圖像加載到一個 numpy 數(shù)組中encoded_contents = np.array(image.getdata()).reshape(        (im_height, im_width, 3)).astype(np.uint8)調整圖像大小 image_np_expanded = np.expand_dims(encoded_contents, axis=0)嘗試構建 json 請求instance = {"input":encoded_contents}row = json.dumps(instance,sort_keys=True)但我無法構建它,因為TypeError(repr(o) + " is not JSON serializable")TypeError: array([[[164, 191, 220],[190, 157, 114],[190, 157, 114]]], dtype=uint8) is not JSON serializable如果我使用 tolist() 方法將 numpy 數(shù)組轉換為列表,則 json 文件需要 3 兆字節(jié)并且 ML 引擎拒絕它“消息”:“請求有效負載大小超過限制:1572864 字節(jié)。”,我會將此 json 作為 json 文件發(fā)送到 ml-engine predict。gcloud ml-engine predict --model=pellaires --version=pellaires14 --json- instances=request.json > response.yaml
查看完整描述

2 回答

?
牧羊人nacy

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

我正在處理的圖像被標準化為 [0,1]。當轉換為列表時,圖像的每個像素都具有不必要的大量精度:


[[[0.4, 0.41568627450980394, 0.4117647058823529],

  [0.39215686274509803, 0.403921568627451, 0.403921568627451],

  [0.38823529411764707, 0.4, 0.4],

  [0.3803921568627451, 0.39215686274509803, 0.3843137254901961],

  [0.3803921568627451, 0.38823529411764707, 0.38823529411764707],

  ...

  [0.11764705882352941, 0.12941176470588237, 0.12549019607843137],

  [0.11764705882352941, 0.12941176470588237, 0.12549019607843137],

  [0.11764705882352941, 0.12941176470588237, 0.12549019607843137]]]

一個快速而骯臟的解決方法是使用 np.around():


img_list = np.around(img_np, 4).tolist()

結果低于有效載荷大小限制。


查看完整回答
反對 回復 2021-07-21
?
繁華開滿天機

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

發(fā)送如此大的整數(shù)數(shù)組通常效率不高(您將花費大量時間編碼和解碼這些數(shù)組、網(wǎng)絡延遲等)。這篇文章提供了一些選項(包括tolist您嘗試過的)。


我會推薦“打包為字節(jié)字符串的張量”或“壓縮圖像數(shù)據(jù)”。


更新 10/19/2018


為了使用這些方法,您需要修改您的圖表。如果您能夠重新導出模型,那是最簡單的。代替:


images = tf.placeholder(dtype=tf.uint8, shape=[None, None, None, 3])

你會使用:


raw_byte_strings = tf.placeholder(dtype=tf.string, shape=[None])

decode = lambda raw_byte_str: tf.decode_raw(raw_byte_str, tf.uint8)

images = tf.map_fn(decode, raw_byte_strings, dtype=tf.uint8)


查看完整回答
反對 回復 2021-07-21
  • 2 回答
  • 0 關注
  • 216 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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