はじめに
皆さん、ComfyUI使ってますか?私は趣味でゲーム制作をしているのですが、その素材をAIで作成できないかと格闘したときにハマってしまったので共有します。
LayerDiffuseとは
このGigazineさんの記事がわかりやすいのでURLを貼り付けておきます。
簡単に言えば透過画像を生成できるようにする拡張機能です。
ちなみにLayerDiffuseはStableDiffusionWebUIForge用であるLayerDiffusionをComfyUIで使えるように改良したものになります。
普通に導入しても動作しない問題
ComfyUIで拡張機能を導入するときは、基本的にはComfyUI-Managerを利用します。
ところが、この手順で導入したものは、拡張機能の読み込みに失敗するようです。
エラー
Traceback (most recent call last):
File "ComfyUI_windows_portable\ComfyUI\nodes.py", line 1993, in load_custom_node
module_spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "ComfyUI_windows_portable\ComfyUI\comfy_extras\nodes_upscale_model.py", line 3, in <module>
from spandrel import ModelLoader, ImageModelDescriptor
ModuleNotFoundError: No module named 'spandrel'
Cannot import ComfyUI_windows_portable\ComfyUI\comfy_extras\nodes_upscale_model.py module for custom nodes: No module named 'spandrel'
Traceback (most recent call last):
File "ComfyUI_windows_portable\ComfyUI\nodes.py", line 1993, in load_custom_node
module_spec.loader.exec_module(module)
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-layerdiffuse\__init__.py", line 1, in <module>
from .layered_diffusion import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
File "ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-layerdiffuse\layered_diffusion.py", line 18, in <module>
from .lib_layerdiffusion.utils import (
File "ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-layerdiffuse\lib_layerdiffusion\utils.py", line 3, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
エラー文を何となく読んでる感じ、モジュールが不足しているみたい。
解決法
Layerdiffuseのrequiments.txtを見ると、diffusersとopencv-pythonが必要と書いてますが、どうやらComfyUIに内蔵しているPythonにはそれが導入されていないようです。
以下のコマンドをComfyUI_windows_portable直下で実行してください。(Portable版じゃない方は各々読み替えてください。)
実行するコマンド
.\python_embeded\python.exe -m pip install diffusers opencv-python
これで正常に読み込めます。