前処理と後処理

注: Maximo® Visual Inspection 8.7以降、カスタム・モデルはサポートされず、カスタム・スクリプトをアップロードできません。 カスタム・モデルは、引き続き Maximo Visual Inspection 8.6 以前のバージョンでサポートされます。 REST API は、 Maximo Visual Inspection 8.6 以前のバージョンにアップロードした既存のカスタム・スクリプトの取得を引き続きサポートします。

手操作による介入なく各推論操作の前後に操作を実行するためのカスタマイズをアップロードできます。

  • custom.py テンプレート
  • オプションの requirements.txt ファイル
  • 前処理、後処理、またはその両方を使用したモデルのデプロイ
注: アクション検出モデルには対応していません。

custom.py テンプレート

custom.py テンプレートを使用して、 custom.pyという名前の 1 つの Python ファイルを生成します。 ファイルには、前処理、後処理、またはその両方の命令を含めることができます。 バージョンは、モデル・タイプによって異なります。

  • 高解像度、異常最適化、およびカスタム・モデル用の Python 2。
  • Python による高速化されたR-CNN、 GoogLeNet,、SSD、 v3、 v3、および Detectron2 モデル。
注: Maximo Visual Inspection9.1 からは、SSD(Single Shot Detector)モデルはモデル学習用としてサポートされなくなりました。 ただし、SSDモデルのインポートおよび配備は、引き続き Maximo Visual Inspection および Maximo Visual Inspection Edge.
重要:このファイルは、.zipファイルの最上位のディレクトリーにcustom.pyファイルが含まれている.zipファイルにパッケージ化されている必要があります。

追加の Python ファイル、シェル・スクリプト、イメージなどのその他のファイルも、.zip ファイルに存在できます。 カスタマイズ・スクリプトがPythonの組み込みモジュール以外のでPythonモジュールを必要とする場合は、pipを使用してインストールされるモジュールのリストを含むrequirements.txtファイルを作成できます。 このテンプレートには次の情報が含まれています。

  • 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 ファイルをアップロードします。 成果物タイプには、カスタム推論スクリプトを選択します。
  2. デプロイしたいモデルに移動し、「 モデルのデプロイ」をクリックします。
  3. 拡張デプロイメント をオンに切り替えます。
  4. 「カスタム推論スクリプト」で、使用する推論スクリプトを選択し、推論結果の処理内容を指定し、「デプロイ」をクリックします。
    注:
    • カスタム推論スクリプトを選択しない場合でも、推論結果を保存できます。
    • 動画の推論結果は保存されません