前處理和後處理

附註:Maximo® Visual Inspection 8.7開始,不支援自訂模型,且無法上傳自訂 Script。 在 Maximo Visual Inspection 8.6 及更舊版本中仍然支援自訂模型。 REST API 仍然支援擷取您上傳至 Maximo Visual Inspection 8.6 及更舊版本的任何現有自訂 Script。

您可以上傳自訂作業,以在每一個推理作業之前和之後執行作業,而不需要人為介入。

  • custom.py 範本
  • 選用 requirements.txt 檔案
  • 部署具有前處理及/或後處理的模型
附註:動作偵測模型不受支援。

custom.py 範本

使用 custom.py 範本來產生一個名為 custom.py的 Python 檔案。 檔案可以包含前置處理及/或後置處理的指示。 版本取決於機型:

  • Python 2 適用於高解析度、異常最佳化及自訂模型。
  • Python 3 for Faster R-CNN、 GoogLeNet、SSD、YOLO v3、小型 YOLO v3及 Detectron2 模型。
附註:Maximo Visual Inspection 8.7開始,不支援自訂模型。 在 Maximo Visual Inspection 8.6 及更舊版本中仍然支援自訂模型。
重要事項: 此檔案必須包裝在 .zip 檔中,該檔案在 .zip 檔的最高層級目錄中有 custom.py 檔案。

.zip 檔案中還可能存在其他檔案(例如,額外的 Python 檔案、Shell Script 及影像)。 如果自訂作業 Script 需要 Python 模組,除了 Python 中的那些內建模組之外,您可以建立一個 requirements.txt 檔案,其中包含要使用 pip 來安裝的模組清單。 範本包含下列資訊:

  • class CustomInference - 檔案中唯一的 Python 類別。 它必須命名為 CustomInference,並保留 "pre" 和 " post" 圖說文字。
  • onPreProcessing - 如果已定義,則此函數必須位於 CustomInference 中。 對影像執行推理之前,會呼叫此函數。
  • onPostProcessing - 如果已定義,則此函數必須位於 CustomInference 中。 對影像執行推理之後,會呼叫此函數。
class CustomInference:
# Callout for inference pre-processing.  Will be called before the
# actual inference on the “image”
#
# Input:
#    image:    Image represented as a NumPy array that inference is to be
#              performed on.
#
# params:  To be used for additional parameters.  This will be
#             a listof key/value pairs.
#
# Output:
#    image:    Return the image represented as a NumPy array that is to
#              be used for inference.  This array may been manipulated
#              in this function, or it may be the same exact NumPy array.
#
def onPreProcessing(self, image, params):

     return image
# Callout for the inference post-processing.  Will be called
# after the image has been inferred.
#
# Input:
#    Image:    Image represented as a NumPy array that inference is to be
#              performed on.
#
# results:  JSON of the inference results.  The JSON will be
#              dependent on thetype of inference.
#
# params: To be used for additional parameters.  This will
#              be a list of key/value pairs
#
# Output:
#    results:  A json object that is a copy of the original
#              inference results.  However, if the callout
#              intends to return additional information, that
#              information can bereturnedin the json results
#              under the key “user”.
#                   
def onPostProcessing(self, image, results, params):

     return results

選用 requirements.txt 檔案

下列範例檔顯示 requirements.txt 檔案的內容:

sseclient==0.0.19
tflearn==0.3.2
keras==2.2.4

部署使用前處理和/或後處理的模型

若要部署使用額外處理的模型,請上傳自訂 .zip 檔案,然後在部署上指定該文件。

  1. 移至自訂構件頁面,並上傳包含 custom.py 的 .zip 檔。 針對構件類型,選取自訂推理 Script
  2. 移至您要部署的模型,然後按一下部署模型
  3. 開啟進階部署
  4. 若為自訂推論 Script,請選取您要使用的推斷 Script,指定您要對推論結果執行的作業,然後按一下部署
    附註:
    • 即使您沒有選擇自訂推理 Script,也可以儲存推理結果。
    • 不儲存影片的推理結果。