0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

背景除去ができる「BEN2」のデモアプリをサクッと試す(Hugging Face 上で試す、Python で使う場合の情報も少し記載)

Last updated at Posted at 2025-02-01

はじめに

以下の記事で見かけた背景除去ができる「BEN2」の話です。

●【生成AIニュース】『TinySwallow-1.5B』『Onlook』『Luma Upscale to 4K』『Alibaba Qwenの動画生成AI』『BEN2』『YuE-s1-7B-anneal-|fujito
 https://note.com/toshia_fuji/n/nb50b1bbca26e

Prama LLC というところが提供しているようです。

公式のリンク

公式のリンクを 2つほど掲載してみます。

デモ

1つ目は今回の主題になるデモアプリです。

●BEN2 - a Hugging Face Space by PramaLLC
 https://huggingface.co/spaces/PramaLLC/BEN2

2025-02-01_10-15-24.jpg

各種情報

公式が各種情報をのせている Hugging Face のページです。

●PramaLLC/BEN2 · Hugging Face
 https://huggingface.co/PramaLLC/BEN2

2025-02-01_10-18-43.jpg

公式デモを試す

それでは、上で掲載している公式デモを使ってみます。

入出力

試しに、この前 ChatGPT で生成した画像を使って、画像に対する背景除去を試してみました。

入力画像

入力画像は以下です。

DALL·E 2025-01-14 19.30.18 - A cute, cartoon-style illustration of a small and slender full-body cat with a transparent or white background. The cat should have delicate and grace.png

使い方

試すのは簡単です。

今回は画像データがあるので、それをデモアプリの左にドラッグアンドドロップで放り込みます。

2025-02-01_10-34-13.jpg

そして「Submit」ボタンを押すと、今回の場合は 2秒くらいで以下の画面になりました。

2025-02-01_10-34-26.jpg

あとは、画面右側のほうから画像をダウンロードできます。

出力

上記の手順で出力された画像は、以下になりましt。

foregroundのコピー.png

透過されている部分が比較しづらいので、パワポ上で色付き背景にしたスライド上に入出力画像を置いてみます。

2025-02-01_10-29-15.jpg

片耳や頭の部分の薄い色の部分が除去対象になってたりしましたが、概ね良い感じに処理できました。

その他

今回は公式デモで試しましたが、上記の Hugging Face のページ内で書かれているように、Python でも使えるようです。

クイックスタート

例えば、「Quick start code (inside cloned repo)」という項目名で、以下のプログラムが掲載されています。

import BEN2
from PIL import Image
import torch


device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

file = "./image.png" # input image

model = BEN2.BEN_Base().to(device).eval() #init pipeline

model.loadcheckpoints("./BEN2_Base.pth")
image = Image.open(file)
foreground = model.inference(image, refine_foreground=False,) #Refine foreground is an extract postprocessing step that increases inference time but can improve matting edges. The default value is False.

foreground.save("./foreground.png")

インストールなどについては、ページ最下部に以下の記載がありました。

2025-02-01_10-23-47.jpg

また、この後に掲載しているように、バッチ処理やビデオを対象にした処理についても記載があります。

バッチ処理

2025-02-01_10-24-43.jpg

ビデオに対する処理

2025-02-01_10-22-44.jpg

その他: 試してみたい別のもの

今回の「BEN2」と同様に、Hugging Face 上で試せて、そして Python で扱える「BRIA RMBG 2.0」も良さそうなので、別途、試してみようと思います。

●briaai/RMBG-2.0 · Hugging Face
 https://huggingface.co/briaai/RMBG-2.0

●BRIA RMBG 2.0 - a Hugging Face Space by briaai
 https://huggingface.co/spaces/briaai/BRIA-RMBG-2.0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?