公開日:2022年7月14日
最終更新日:2022年9月11日
はじめに
CLIP(Contrastive Language-Image Pre-Training)は自然言語処理の技術を用いた学習済み画像分類モデルです。「ゼロショット画像分類(Zero-Shot Image Classification)」と言われ、一般に公開されている画像分類のためのデータセットに含まれないものまで分類できるのが特徴のようです。
AutoGluonで、このモデルが簡単に使用できるようになっています。
Pythonスクリプト
version ≦0.5.2
from autogluon.multimodal import download, MultiModalPredictor url = "https://live.staticflickr.com/7236/7114602897_9cf00b2820_b.jpg" segway_image = download(url) predictor = MultiModalPredictor(hyperparameters={"model.names": ["clip"]}, problem_type="zero_shot") text_list = ['segway', 'bicycle', 'wheel', 'car'] prob = predictor.predict_proba({"image": [segway_image]}, {"text": text_list}) maxIndex = prob.argmax() print(f"{text_list[maxIndex]}:{prob[0][maxIndex]:.6f}")
version >0.5.2
from autogluon.multimodal import download, MultiModalPredictor url = "https://live.staticflickr.com/7236/7114602897_9cf00b2820_b.jpg" segway_image = download(url) predictor = MultiModalPredictor(pipeline="zero_shot_image_classification") text_list = ['segway', 'bicycle', 'wheel', 'car'] prob = predictor.predict_proba({"image": [segway_image]}, {"text": text_list}) maxIndex = prob.argmax() print(f"{text_list[maxIndex]}:{prob[0][maxIndex]:.6f}")
候補となるクラス名(または文章)を与えてあげる必要があります。
上記スクリプトのこの部分です。
text_list = ['segway', 'bicycle', 'wheel', 'car']
結果

segway:0.999972
動作環境
Ubuntu 20.04 on WSL2 CUDA 11.3.1 Python 3.9.5
インストールしたのはPyTorchとAutoGluonのみです。