LoginSignup
1
1

More than 1 year has passed since last update.

BodyPixやーる(Python3.6、Tensorflow、Windows10)

Last updated at Posted at 2021-05-29

はじめに

BodyPixをやっていきます。

開発環境

  • Windows 10
  • Python 3.6
  • anaconda

導入

1.anacondaでPython3.6環境を作り、ライブラリをインストールします。

pip install tf-bodypix
pip install tensorflow
pip install tfjs-graph-converter

2.下記のコードを書いて、入力画像を用意します。

import tensorflow as tf
from tf_bodypix.api import download_model, load_model, BodyPixModelPaths

bodypix_model = load_model(download_model(
    BodyPixModelPaths.MOBILENET_FLOAT_50_STRIDE_16
))

root = "input-image"
ext = ".jpg"

image = tf.keras.preprocessing.image.load_img(
    f'./input/{root}{ext}'
)
image_array = tf.keras.preprocessing.image.img_to_array(image)
result = bodypix_model.predict_single(image_array)
mask = result.get_mask(threshold=0.75)
tf.keras.preprocessing.image.save_img(
    f'./output/{root}-mask{ext}',
    mask
)

colored_mask = result.get_colored_part_mask(mask)
tf.keras.preprocessing.image.save_img(
    f'./output/{root}-colored-mask{ext}',
    colored_mask
)

実行結果

入力 マスク画像 マスク画像(カラー)
AdobeStock_246496748.jpeg AdobeStock_246496748-mask.jpeg AdobeStock_246496748-colored-mask.jpeg

お疲れ様でした

1
1
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
1
1