簡體   English   中英

了解tflite model的輸入和output

[英]Understanding input and output of tflite model

我是 Tensorflow 的新手,並試圖將其合並到我的項目中。 我正在使用帶有攝像頭的樹莓派 pi4 來檢測我的喂鳥器的變化,拍照,然后用 tensorflow 識別那只鳥。 我正在使用Birds_V1來完成此任務。

我很好奇如何解釋輸入和 output。 根據概述,輸入為:

預計是大小為 224 x 224 的 3 通道 RGB 彩色圖像,縮放為 [0, 1]。

我對縮放到 [0,1] 的含義感到困惑此外,output

image_classifier:一個965維的概率向量,對應labelmap中的背景class和964種鳥類。

我完全迷失了這里的意思。

最后,我運行了interpreter.get_input_details() 和interpreter.get_output_details() 來看看它對我來說是什么output。

我把這個打印回來了,頂部是輸入,底部是 output:

[{'name': 'module/hub_input/images_uint8', 'index': 170, 'shape': array([  1, 224, 224,   3]), 'dtype': <class 'numpy.uint8'>, 'quantization': (0.0078125, 128), 'quantization_parameters': {'scales': array([0.0078125], dtype=float32), 'zero_points': array([128]), 'quantized_dimension': 0}}]

[{'name': 'module/prediction', 'index': 171, 'shape': array([  1, 965]), 'dtype': <class 'numpy.uint8'>, 'quantization': (0.00390625, 0), 'quantization_parameters': {'scales': array([0.00390625], dtype=float32), 'zero_points': array([0]), 'quantized_dimension': 0}}]

我不知道如何解釋這一點,並且想知道我是否應該放棄它或者如果它不重要則忽略它。

我很欣賞可以對此任何部分進行的任何澄清,並感謝您認為對解決此問題有用的任何資源。 我一直在尋求幫助,但還沒有得到任何幫助。

@smile 在評論中回答了大多數問題,但為了社區的利益,在此處(回答部分)提供了澄清。

問題:我對縮放到 [0,1] 的含義感到困惑

:通常, Images只是一個Numpy Array (在您的形狀為 224、224、3 的情況下),其值范圍從0 to 255 我們通過將每個像素值除以 255 來Normalize Pixel Values ,以便每個Pixel的值都在[0,1]范圍內。 如果我們不對Pixel Values進行NormalizeModel Converge所需的時間會非常長。

有關規范化的更多信息,請參閱此Stack Overflow Answer和此Stack Exchange Answer

問題:維數為 965 的probability vector ,對應於背景class和 label map 中的 964 種鳥類。 我完全迷失了這里的意思。

:在我們 CNN 的最后一層,我們將使用Softmax Activation Function ,其Number of Units等於Number of Classes (在您的情況下,其值為965 )。 因此,該LayerOutput將產生 965 個Probabilities ,所有Probabilities之和為 1。 Probability最高的Class表示對應於該Image AFZ 的Class

例如,在 5 種model output = [0.1,0.1,0.6, 0.1, 0.1]分別對應於[A,B,C,D,E]物種中。 這意味着輸入圖像被分類為物種 C(最大值 0.6)。 (以@smile 為例,解釋得很好)。

問題:我不知道如何解釋interpreter.get_input_detailsinterpreter.get_output_details

答案get_input_details的源代碼解釋說它返回一個我們的輸入圖像張量的所有細節的列表 同樣, get_output_details的源代碼解釋說它返回了我們的 Output 預測張量的所有細節的列表 有關 API 解釋器的信息,請參閱此Tensorflow 文檔

所以在代碼中,

[{'name': 'module/hub_input/images_uint8', 'index': 170, 

'shape': array([  1, 224, 224,   3]), 'dtype': <class 'numpy.uint8'>, 

'quantization': (0.0078125, 128), 'quantization_parameters': {'scales': 

array([0.0078125], dtype=float32), 'zero_points': array([128]), 

'quantized_dimension': 0}}]

Name表示圖中輸入張量的NameShape表示其shape Quantization的目的是減小Model的大小,因為Mobile DevicesMemory會更小。 有關Quantization的更多信息,請參閱此Tensorflow 文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM