iinfer.app package
Subpackages
- iinfer.app.predicts package
- Submodules
- iinfer.app.predicts.insightface_det module
- iinfer.app.predicts.mmdet_det_YoloX module
- iinfer.app.predicts.mmdet_det_YoloX_Lite module
- iinfer.app.predicts.mmpretrain_cls_swin module
- iinfer.app.predicts.mmpretrain_cls_swin_Lite module
- iinfer.app.predicts.mmseg_seg_PSPNet module
- iinfer.app.predicts.mmseg_seg_San module
- iinfer.app.predicts.mmseg_seg_SwinUpernet module
- iinfer.app.predicts.onnx_cls_EfficientNet_Lite4 module
- iinfer.app.predicts.onnx_det_TinyYoloV3 module
- iinfer.app.predicts.onnx_det_YoloV3 module
- iinfer.app.predicts.onnx_det_YoloX module
- iinfer.app.predicts.onnx_det_YoloX_Lite module
- Module contents
Submodules
iinfer.app.app module
- class iinfer.app.app.IinferApp(appcls=None, ver=<module 'cmdbox.version' from 'C:\\Users\\hama\\OneDrive\\デスクトップ\\devenv\\iinfer\\.venv\\Lib\\site-packages\\cmdbox\\version.py'>, cli_features_packages: ~typing.List[str] = None, cli_features_prefix: ~typing.List[str] = None)[source]
Bases:
CmdBoxApp
iinfer.app.client module
- class iinfer.app.client.Client(logger: Logger, redis_host: str = 'localhost', redis_port: int = 6379, redis_password: str = None, svname: str = 'server')[source]
Bases:
Client
- capture(capture_device='0', image_type: str = 'capture', capture_frame_width: int = None, capture_frame_height: int = None, capture_fps: int = 1000, output_preview: bool = False)[source]
ビデオをキャプチャしてその結果を出力する
- Parameters:
capture_device (int or str) -- キャプチャするディバイス、ビデオデバイスのID, ビデオファイルのパス。rtspのURL. by default 0
image_type (str, optional) -- 画像の形式. Defaults to 'capture'.
capture_frame_width (int) -- キャプチャするビデオのフレーム幅, by default None
capture_frame_height (int) -- キャプチャするビデオのフレーム高さ, by default None
capture_fps (int) -- キャプチャするビデオのフレームレート, by default 1000
output_preview (bool, optional) -- 予測結果の画像をプレビューするかどうか. Defaults to False.
- deploy(name: str, model_img_width: int, model_img_height: int, model_file: str, model_conf_file: List[Path], predict_type: str, custom_predict_py: Path, label_file: Path, color_file: Path, before_injection_conf: Path, before_injection_type: List[str], before_injection_py: List[Path], after_injection_conf: Path, after_injection_type: List[str], after_injection_py: List[Path], train_dataset: Path, train_dataset_upload: bool, train_type: str, custom_train_py: Path, overwrite: bool, retry_count: int = 3, retry_interval: int = 5, timeout: int = 60)[source]
モデルをRedisサーバーにデプロイする
- Parameters:
name (str) -- モデル名
model_img_width (int) -- 画像の幅
model_img_height (int) -- 画像の高さ
model_file (str) -- モデルファイルのパス又はURL
model_conf_file (List[Path]) -- モデル設定ファイルのパス
predict_type (str) -- 推論方法のタイプ
custom_predict_py (Path) -- 推論スクリプトのパス
label_file (Path) -- ラベルファイルのパス
color_file (Path) -- 色ファイルのパス
before_injection_conf (Path) -- 推論前処理設定ファイルのパス
before_injection_type (List[str]) -- 推論前処理タイプ
before_injection_py (List[Path]) -- 推論前処理スクリプトのパス
after_injection_type (List[str]) -- 推論後処理タイプ
after_injection_conf (Path) -- 推論後処理設定ファイルのパス
after_injection_py (List[Path]) -- 推論後処理スクリプトのパス
train_dataset (Path) -- 学習データセットディレクトリのパス
train_dataset_upload (bool) -- 学習データセットをサーバーにアップロードするかどうか
train_type (str) -- 学習方法のタイプ
custom_train_py (Path) -- 学習スクリプトのパス
overwrite (bool) -- モデルを上書きするかどうか
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 60.
- Returns:
Redisサーバーからの応答
- Return type:
dict
- deploy_list(retry_count: int = 3, retry_interval: int = 5, timeout: int = 60)[source]
デプロイされたモデルのリストを取得する
- Parameters:
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 60.
- Returns:
Redisサーバーからの応答
- Return type:
dict
- predict(name: str, image=None, image_file=None, image_file_enable: bool = True, pred_input_type: str = 'jpeg', output_image_file: str = None, output_preview: bool = False, nodraw: bool = False, retry_count: int = 3, retry_interval: int = 5, timeout: int = 60)[source]
画像をRedisサーバーに送信し、推論結果を取得する
- Parameters:
name (str) -- モデル名
image (np.ndarray | bytes, optional) -- 画像データ. Defaults to None. np.ndarray型の場合はデコードしない(RGBであること).
image_file (str|file-like object, optional) -- 画像ファイルのパス. Defaults to None.
image_file_enable (bool, optional) -- 画像ファイルを使用するかどうか. Defaults to True. image_fileがNoneでなく、このパラメーターがTrueの場合はimage_fileを使用する.
pred_input_type (str, optional) -- 画像の形式. Defaults to 'jpeg'.
output_image_file (str, optional) -- 予測結果の画像ファイルのパス. Defaults to None.
output_preview (bool, optional) -- 予測結果の画像をプレビューするかどうか. Defaults to False.
nodraw (bool, optional) -- 描画フラグ. Defaults to False.
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 60.
- Returns:
Redisサーバーからの応答
- Return type:
dict
- read_dir(glob_str: str, read_input_type: str = 'jpeg', image_type: str = 'capture', root_dir: Path = WindowsPath('.'), include_hidden=True, moveto: Path = None, polling: bool = False, polling_count: int = 10, polling_interval: int = 1)[source]
ディレクトリ内の画像ファイルを取得します
- Parameters:
glob_str (str) -- 読込むファイルのglobパターン
read_input_type (str, optional) -- 読み込みタイプ. Defaults to 'jpeg'.
image_type (str, optional) -- 画像の形式. Defaults to 'capture'.
root_dir (Path, optional) -- 検索の基準となるルートディレクトリ. Defaults to Path('.').
include_hidden (bool, optional) -- 隠しファイルを含めるかどうか. Defaults to True.
moveto (Path, optional) -- 読み込んだファイルを移動する先のディレクトリ. Defaults to None.
polling (bool, optional) -- 定期的にディレクトリ内の読込みを繰り返すかどうか. Defaults to False.
polling_count (int, optional) -- ポーリング回数. Defaults to 10.
polling_interval (int, optional) -- ポーリング間隔. Defaults to 1.
- Yields:
Tuple[str, str, int, int, int, str] -- 画像の形式, 画像のBase64文字列, 画像の高さ, 画像の幅, 画像の色数, 画像のファイル名
- start(name: str, model_provider: str = 'CPUExecutionProvider', use_track: bool = False, gpuid: int = None, retry_count: int = 3, retry_interval: int = 5, timeout: int = 60)[source]
モデルをRedisサーバーで起動する
- Parameters:
name (str) -- モデル名
model_provider (str, optional) -- 推論実行時のモデルプロバイダー。デフォルトは'CPUExecutionProvider'。
use_track (bool) -- Multi Object Trackerを使用するかどうか, by default False
gpuid (int) -- GPU ID, by default None
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 60.
- Returns:
Redisサーバーからの応答
- Return type:
dict
- stop(name: str, retry_count: int = 3, retry_interval: int = 5, timeout: int = 60)[source]
モデルをRedisサーバーで停止する
- Parameters:
name (str) -- モデル名
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 60.
- Returns:
Redisサーバーからの応答
- Return type:
dict
- stop_server(retry_count: int = 3, retry_interval: int = 5, timeout: int = 60)[source]
Redisサーバーを停止する
- Parameters:
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 60.
- Returns:
Redisサーバーからの応答
- Return type:
dict
- train(name: str, overwrite: bool, retry_count: int = 3, retry_interval: int = 5, timeout: int = 10800)[source]
モデルをRedisサーバーで学習する
- Parameters:
name (str) -- モデル名
overwrite (bool) -- モデルを上書きするかどうか
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 3*3600.
- Returns:
Redisサーバーからの応答
- Return type:
dict
- undeploy(name: str, retry_count: int = 3, retry_interval: int = 5, timeout: int = 60)[source]
モデルをRedisサーバーからアンデプロイする
- Parameters:
name (str) -- モデル名
retry_count (int, optional) -- リトライ回数. Defaults to 3.
retry_interval (int, optional) -- リトライ間隔. Defaults to 5.
timeout (int, optional) -- タイムアウト時間. Defaults to 60.
- Returns:
Redisサーバーからの応答
- Return type:
dict
iinfer.app.common module
- iinfer.app.common.draw_boxes(image: Image, boxes: List[List[float]], scores: List[float], classes: List[int], ids: List[str] = None, labels: List[str] = None, colors: List[Tuple[int]] = None, tracks: List[int] = None, nodraw: bool = False, nolookup: bool = False) Tuple[Image, List[str]] [source]
画像にバウンディングボックスを描画します。
- Parameters:
image (Image.Image) -- 描画する画像
boxes (List[List[float]]) -- バウンディングボックスの座標リスト
scores (List[float]) -- 各バウンディングボックスのスコアリスト
classes (List[int]) -- 各バウンディングボックスのクラスリスト
ids (List[str]) -- 各バウンディングボックスのIDリスト
labels (List[str], optional) -- クラスのラベルリスト. Defaults to None.
colors (List[Tuple[int]], optional) -- クラスごとの色のリスト. Defaults to None.
tracks (List[int], optional) -- トラックIDリスト. Defaults to None.
nodraw (bool, optional) -- 描画しない場合はTrue. Defaults to False.
nolookup (bool, optional) -- ラベル及び色をクラスIDから取得しない場合はTrue. Defaults to False.
- Returns:
バウンディングボックスが描画された画像 List[str]: 各バウンディングボックスのラベルリスト
- Return type:
Image
iinfer.app.injection module
- class iinfer.app.injection.AfterInjection(config: Dict[str, Any], logger: Logger)[source]
Bases:
Injection
サーバーサイドで実行する後処理を実装するためのクラスです。
- action(reskey: str, name: str, outputs: Dict[str, Any], output_image: Image, session: Dict[str, Any]) Tuple[Dict[str, Any], Image] [source]
このメソッドは推論を実行した後の処理を実行します。
- Parameters:
reskey (str) -- レスポンスキー
name (str) -- モデル名
outputs (Dict[str, Any]) -- 推論結果。次の項目が含まれます。 ・success or warn: 推論成功か警告のキーに対して、その内容が格納されます。 ・output_image: 推論後の画像データをbase64エンコードした文字列 ・output_image_shape: 推論後の画像データの形状(base46でコードするときに必要) ・output_image_name: クライアントから指定されてきた推論後の画像データの名前
output_image (Image.Image) -- 推論後の画像データ
session (Dict[str, Any]) -- 推論セッション。次の項目が含まれます。 ・session: app.predict.Predict#create_session() で作成されたセッション ・model_img_width: モデルの入力画像の幅 ・model_img_height: モデルの入力画像の高さ ・predict_obj: app.predict.Predict インスタンス ・labels: クラスラベルのリスト ・colors: ボックスの色のリスト ・tracker: use_trackがTrueの場合、トラッカーのインスタンス
- Returns:
後処理後の推論結果と画像データのタプル
- Return type:
Tuple[Dict[str, Any], Image.Image]
- class iinfer.app.injection.BeforeInjection(config: Dict[str, Any], logger: Logger)[source]
Bases:
Injection
サーバーサイドで実行する前処理を実装するためのクラスです。
- action(reskey: str, name: str, image: Image, session: Dict[str, Any]) Image [source]
このメソッドは推論を実行する前処理を実行します。
- Parameters:
reskey (str) -- レスポンスキー
name (str) -- モデル名
image (Image.Image) -- 推論する画像データ
session (Dict[str, Any]) -- 推論セッション。次の項目が含まれます。
・session -- app.predict.Predict#create_session() で作成されたセッション
・model_img_width -- モデルの入力画像の幅
・model_img_height -- モデルの入力画像の高さ
・predict_obj -- app.predict.Predict インスタンス
・labels -- クラスラベルのリスト
・colors -- ボックスの色のリスト
・tracker -- use_trackがTrueの場合、トラッカーのインスタンス
- Returns:
前処理後の画像データ
- Return type:
Image.Image
- class iinfer.app.injection.Injection(config: Dict[str, Any], logger: Logger)[source]
Bases:
object
- add_success(outputs: Dict[str, Any], message: Any)[source]
成功メッセージを追加します。
- Parameters:
outputs (Dict[str, Any]) -- 推論結果
message (Any) -- 成功メッセージ
iinfer.app.install module
- class iinfer.app.install.Install(logger: Logger, wsl_name: str = None, wsl_user: str = None)[source]
Bases:
object
- server(data: Path, install_cmdbox_tgt: str = 'cmdbox', install_iinfer_tgt: str = 'iinfer', install_onnx: bool = True, install_mmdet: bool = True, install_mmseg: bool = True, install_mmcls: bool = False, install_mmpretrain: bool = True, install_insightface=False, install_from: str = None, install_no_python: bool = False, install_compile_python: bool = False, install_tag: str = None, install_use_gpu: bool = False)[source]
iinferが含まれるdockerイメージをインストールします。
- Parameters:
data (Path) -- iinfer-serverのデータディレクトリ
install_cmdbox_tgt (str) -- cmdboxのインストール元
install_iinfer_tgt (str) -- iinferのインストール元
install_onnx (bool) -- onnxをインストールするかどうか
install_mmdet (bool) -- mmdetをインストールするかどうか
install_mmseg (bool) -- mmsegをインストールするかどうか
install_mmcls (bool) -- mmclsをインストールするかどうか
install_mmpretrain (bool) -- mmpretrainをインストールするかどうか
install_insightface (bool) -- insightfaceをインストールするかどうか
install_from (str) -- インストール元dockerイメージ
install_no_python (bool) -- pythonをインストールしない
install_compile_python (bool) -- pythonをコンパイルしてインストール
install_tag (str) -- インストールタグ
install_use_gpu (bool) -- GPUを使用するモジュール構成でインストールします。
- Returns:
処理結果
- Return type:
dict
iinfer.app.postprocess module
- class iinfer.app.postprocess.Postprocess(logger: Logger)[source]
Bases:
object
iinfer.app.predict module
- class iinfer.app.predict.OnnxPredict(logger: Logger)[source]
Bases:
Predict
- is_gpu_available(model_path: Path | Any, model_conf_path: Path, gpu_id: int = None) bool [source]
GPUが利用可能かどうかを返す関数です。 戻り値がTrueの場合、GPUが利用可能です。 戻り値がFalseの場合、GPUが利用不可です。
- Parameters:
model_path (Path|Any) -- モデルファイルのパス
model_conf_path (Path) -- モデル設定ファイルのパス
gpu_id (int, optional) -- GPU ID. Defaults to None.
- Returns:
GPUが利用可能かどうか
- Return type:
bool
- class iinfer.app.predict.Predict(logger: Logger)[source]
Bases:
object
- create_session(deploy_dir: Path, model_path: Path | Any, model_conf_path: Path, model_provider: str, gpu_id: int = None) Any [source]
推論セッションを作成する関数です。 startコマンド実行時に呼び出されます。 この関数内でAIモデルのロードを行い、推論準備を完了するようにしてください。 戻り値の推論セッションの型は問いません。
- Parameters:
deploy_dir (Path) -- デプロイディレクトリのパス
model_path (Path|Any) -- モデルファイルのパス
model_conf_path (Path) -- モデル設定ファイルのパス
gpu_id (int, optional) -- GPU ID. Defaults to None.
- Returns:
推論セッション
- is_gpu_available(gpu_id: int = None) bool [source]
GPUが利用可能かどうかを返す関数です。 戻り値がTrueの場合、GPUが利用可能です。 戻り値がFalseの場合、GPUが利用不可です。
- Parameters:
gpu_id (int, optional) -- GPU ID. Defaults to None.
- Returns:
GPUが利用可能かどうか
- Return type:
bool
- post_deploy(deploy_dir: Path, conf: dict) None [source]
デプロイ後の処理を行う関数です。 deployコマンド実行時に呼び出されます。 この関数内でデプロイ後の処理を実装してください。
- Parameters:
deploy_dir (Path) -- デプロイディレクトリのパス
conf (dict) -- デプロイ設定
- predict(session, img_width: int, img_height: int, image: Image, labels: List[str] = None, colors: List[Tuple[int]] = None, nodraw: bool = False) Tuple[Dict[str, Any], Image] [source]
予測を行う関数です。 predictコマンドやcaptureコマンド実行時に呼び出されます。 引数のimageはRGBですので、戻り値の出力画像もRGBにしてください。 戻り値の推論結果のdictは、通常推論結果項目ごとに値(list)を設定します。 例)Image Classification(EfficientNet_Lite4)の場合 return dict(output_scores=output_scores, output_classes=output_classes), image_obj 例)Object Detection(YoloX)の場合 return dict(output_boxes=final_boxes, output_scores=final_scores, output_classes=final_cls_inds), output_image
- Parameters:
session -- 推論セッション
img_width (int) -- モデルのINPUTサイズ(画像の幅)
img_height (int) -- モデルのINPUTサイズ(画像の高さ)
image (Image) -- 入力画像(RGB配列であること)
labels (List[str], optional) -- クラスラベルのリスト. Defaults to None.
colors (List[Tuple[int]], optional) -- ボックスの色のリスト. Defaults to None.
nodraw (bool, optional) -- 描画フラグ. Defaults to False.
- Returns:
予測結果と出力画像(RGB)のタプル
- Return type:
Tuple[Dict[str, Any], Image]
- class iinfer.app.predict.TorchPredict(logger: Logger)[source]
Bases:
Predict
- is_gpu_available(model_path: Path | Any, model_conf_path: Path, gpu_id: int = None) bool [source]
GPUが利用可能かどうかを返す関数です。 戻り値がTrueの場合、GPUが利用可能です。 戻り値がFalseの場合、GPUが利用不可です。
- Parameters:
model_path (Path|Any) -- モデルファイルのパス
model_conf_path (Path) -- モデル設定ファイルのパス
gpu_id (int, optional) -- GPU ID. Defaults to None.
- Returns:
GPUが利用可能かどうか
- Return type:
bool
iinfer.app.redis module
iinfer.app.train module
- class iinfer.app.train.OnnxTrain(logger: Logger)[source]
Bases:
Train
- is_gpu_available(model_path: Path | Any, model_conf_path: Path, gpu_id: int = None) bool [source]
GPUが利用可能かどうかを返す関数です。 戻り値がTrueの場合、GPUが利用可能です。 戻り値がFalseの場合、GPUが利用不可です。
- Parameters:
model_path (Path|Any) -- モデルファイルのパス
model_conf_path (Path) -- モデル設定ファイルのパス
gpu_id (int, optional) -- GPU ID. Defaults to None.
- Returns:
GPUが利用可能かどうか
- Return type:
bool
- class iinfer.app.train.TorchTrain(logger: Logger)[source]
Bases:
Train
- is_gpu_available(model_path: Path | Any, model_conf_path: Path, gpu_id: int = None) bool [source]
GPUが利用可能かどうかを返す関数です。 戻り値がTrueの場合、GPUが利用可能です。 戻り値がFalseの場合、GPUが利用不可です。
- Parameters:
model_path (Path|Any) -- モデルファイルのパス
model_conf_path (Path) -- モデル設定ファイルのパス
gpu_id (int, optional) -- GPU ID. Defaults to None.
- Returns:
GPUが利用可能かどうか
- Return type:
bool
- class iinfer.app.train.Train(logger: Logger)[source]
Bases:
object
- is_gpu_available(gpu_id: int = None) bool [source]
GPUが利用可能かどうかを返す関数です。 戻り値がTrueの場合、GPUが利用可能です。 戻り値がFalseの場合、GPUが利用不可です。
- Parameters:
gpu_id (int, optional) -- GPU ID. Defaults to None.
- Returns:
GPUが利用可能かどうか
- Return type:
bool
- post_train(deploy_dir: Path, conf: dict) None [source]
学習後の処理を行う関数です。 trainコマンド実行時に呼び出されます。 この関数内で学習後の処理を実装してください。
- Parameters:
deploy_dir (Path) -- 学習ディレクトリのパス
conf (dict) -- 学習設定
- train(deploy_dir: Path, model_conf_path: Path, train_cfg_options: Dict[str, Any] = None) None [source]
学習を実行する関数です。 trainコマンド実行時に呼び出されます。 この関数内でAIモデルの学習を行い完了するようにしてください。
- Parameters:
deploy_dir (Path) -- デプロイディレクトリのパス
model_conf_path (Path) -- モデル設定ファイルのパス
train_cfg_options (Dict[str, Any]) -- 学習設定オプションのリスト
iinfer.app.web module
- class iinfer.app.web.Web(logger: Logger, data: Path, appcls=None, ver=None, redis_host: str = 'localhost', redis_port: int = 6379, redis_password: str = None, svname: str = 'server', client_only: bool = False, doc_root: Path = None, gui_html: str = None, filer_html: str = None, assets: List[str] = None, signin_html: str = None, signin_file: str = None, gui_mode: bool = False, web_features_packages: List[str] = [], web_features_prefix: List[str] = [], showimg_html: str = None, webcap_html: str = None, anno_html: str = None)[source]
Bases:
Web
- webcap(allow_host: str = '0.0.0.0', listen_webcap_port: int = 8082, image_type: str = 'capture', outputs_key: List[str] = None, capture_frame_width: int = None, capture_frame_height: int = None, capture_count: int = 5, capture_fps: int = 5)[source]
Webキャプチャを起動する
- Parameters:
allow_host (str, optional) -- 許可ホスト. Defaults to "
listen_webcap_port (int, optional) -- リスンポート. Defaults to 8082.
image_type (str, optional) -- 画像タイプ. Defaults to 'capture'.
outputs_key (list, optional) -- 出力キー. Defaults to None.
capture_frame_width (int, optional) -- キャプチャフレーム幅. Defaults to None.
capture_frame_height (int, optional) -- キャプチャフレーム高さ. Defaults to None.
capture_count (int, optional) -- キャプチャ回数. Defaults to 5.
capture_fps (int, optional) -- キャプチャFPS. Defaults to 5.