LoginSignup
0
0

Oracle DB 23ai の AI Vector Search で画像関連のモデルはまだ使えませんよ、という話

Last updated at Posted at 2024-05-22

Oracel Database 23ai の AI Vector Search を使った画像データの類似検索についてポストしようと準備していましたが、どうやら5/15現在 Resnet-50 などの画像関連モデルが使用できない模様。
同じようなことを試してる方・試そうとしている方がいるんじゃないかと思い、具体的にどこで詰んでしまうか解説します。

(やろうとしていた) ユースケース

・Google Open Images Dataset の画像データセットを Oracle DB 23ai に格納
・実家の愛猫、サスケの写真に類似した画像を抽出

qiita1.png

実施手順とどこで詰むか

手順の大きな流れは次の通りです。

  1. Oracle DB 23ai の構築
  2. データの準備と格納 (4.の前ならいつでも)
  3. 使用するモデルを ONNXフォーマットで export、DBに import
  4. import したモデルで格納したデータの Embedding
  5. 類似検索

画像関連モデルを試そうとすると 3. で詰んでしまいました。
使用するモデルのエクスポートには、OML4py を使用して下記を実行する必要があります。
(OML4py についてはこちら)

$ python3

>>> from oml.utils import EmbeddingModel, EmbeddingModelConfig
>>> config = EmbeddingModelConfig.from_template("text",max_seq_length=512,quantize_model=True)
>>> em = EmbeddingModel(model_name="foo", config=config)
>>> em.export2file("zoo",output_dir=".")

上記を実行して出力された ONNXフォーマットのモデルをDBにインポートする必要がありますが、model_name に microsoft/resnet-50 を指定したところ下記のようなエラーになりました。

/root/miniconda3/envs/rag/lib/python3.12/site-packages/huggingface_hub/file_download.py:1132: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
  warnings.warn(
config.json: 100%|██████████████████████████| 69.6k/69.6k [00:00<00:00, 457kB/s]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "oml/utils/embeddings.py", line 259, in oml.utils.embeddings.EmbeddingModel.export2file
  File "oml/utils/_pipeline/pipeline.py", line 51, in oml.utils._pipeline.pipeline.Pipeline.execute
  File "oml/utils/_pipeline/steps.py", line 139, in oml.utils._pipeline.steps.HFDownloadStep.process
  File "oml/utils/_pipeline/steps.py", line 222, in oml.utils._pipeline.steps.SentenceDownloadStep._downloadModel
  File "/root/miniconda3/envs/rag/lib/python3.12/site-packages/transformers/models/auto/tokenization_auto.py", line 878, in from_pretrained
    tokenizer_class_py, tokenizer_class_fast = TOKENIZER_MAPPING[type(config)]
                                               ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/root/miniconda3/envs/rag/lib/python3.12/site-packages/transformers/models/auto/auto_factory.py", line 742, in __getitem__
    raise KeyError(key)
KeyError: <class 'transformers.models.resnet.configuration_resnet.ResNetConfig'>

google-bert/bert-base-multilingual-cased や sentence-transformers/all-MiniLM-L6-v2 は問題なくエクスポートできるので、hugging face との疎通などに問題があるわけではなさそう…
パラメータを増やしたり減らしたり変更しても状況は変わらず、改めてマニュアルを確認してみると…

qiita2.jpg

Limitations
Transformer Model Type Currently supported only for text transformers.

ということで、現時点ではテキスト関連モデルのみサポート (利用可) のようです。
解説記事一番乗りを目指していましたが、残念…
できるようになったら改めてポストします。

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