7
4

More than 1 year has passed since last update.

服をセグメンテーションする cloth segmentation

Last updated at Posted at 2022-02-21

画像の中の服の領域だけを検出・分離する方法です

衣服用のアプリケーションが作りたい

ファッションEC、試着アプリなど、服のセグメンテーションを行うことで、さまざまなアプリケーションが作れます。

機械学習で服の領域を検出

セマンティック・セグメンテーションを用いれば、自動で服の領域を検出できます。

以下のモデルを用いて、Pythonで手軽に実行できます。

また、CoreML形式に変換したモデルを使うことで、iOS、MacOSデバイス上でも実行でき、iOSアプリに適用できます。

方法

Python

インストールから実行まで、Colabが用意されています。

推論ファイルから実行する場合。

python -m torch.distributed.launch --nproc_per_node=<num_gpu> cloths_segmentation/inference.py \
                                   -i <path to images> \
                                   -c <path to config> \
                                   -w <path to weights> \
                                   -o <output-path> \
                                   --fp16

試すだけなら、Webアプリも用意されています。

Swift

iOSで実行するには、CoreML-ModelsからCoreMLモデルをダウンロードしてプロジェクトにバンドルします。

let model = try! VNCoreMLModel(for: clothSegmentation(configuration: MLModelConfiguration()).model)
let coreMLRequest:VNCoreMLRequest = VNCoreMLRequest(model: model)

let handler = VNImageRequestHandler(ciImage: ciimage,options: [:])
try! handler.perform([coreMLRequest])
let result = request.results?.first as! VNPixelBufferObservation
let pixelBuffer = result.pixelBuffer

精度も良い

なかなか精度も良いので、便利なアプリケーションが作れそうです。

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLやARKitを使ったアプリを作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium

7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4