見出し画像

stable diffusion webui 1.3環境のSuperMergerでSequential XY Merge and Generationがエラーを吐く事への対策

はじめに

stable diffusion webui を1.3にアップデートしたところSuperMergerでSequential XY Merge and Generationがエラーを吐くようになってしまいました
今回の対策は朝霧ちしゃさんの記事にあるpaperspace用の対策をベースに自分のローカル環境に合わせて改変したものになります

原因と対策

エラー内容

Traceback (most recent call last):
  File "C:\StableDiffusion\stable-diffusion-webui\extensions\sd-webui-supermerger\scripts\mergers\mergers.py", line 565, in get_font
    from fonts.ttf import Roboto
ModuleNotFoundError: No module named 'fonts'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\StableDiffusion\stable-diffusion-webui\extensions\sd-webui-supermerger\scripts\mergers\mergers.py", line 572, in get_font
    return ImageFont.truetype(shared.opts.font or 'javascript/roboto.ttf', fontsize)
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\PIL\ImageFont.py", line 996, in truetype
    return freetype(font)
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\PIL\ImageFont.py", line 993, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\PIL\ImageFont.py", line 248, in __init__
    self.font = core.getfont(
OSError: cannot open resource

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\routes.py", line 422, in run_predict
    output = await app.get_blocks().process_api(
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1323, in process_api
    result = await self.call_function(
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\gradio\blocks.py", line 1051, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "C:\StableDiffusion\stable-diffusion-webui\extensions\sd-webui-supermerger\scripts\mergers\xyplot.py", line 52, in numanager
    result,currentmodel,xyimage,a,b,c= sgenxyplot(xtype,xmen,ytype,ymen,esettings,
  File "C:\StableDiffusion\stable-diffusion-webui\extensions\sd-webui-supermerger\scripts\mergers\xyplot.py", line 320, in sgenxyplot
    image_temp = simggen(prompt, nprompt, steps, sampler, cfg, seed, w, h,hireson,hrupscaler,hr2ndsteps,denoise_str,hr_scale,batch_size,currentmodel,id_sets,modelid)
  File "C:\StableDiffusion\stable-diffusion-webui\extensions\sd-webui-supermerger\scripts\mergers\mergers.py", line 681, in simggen
    processed.images[i] = draw_origin(image, str(modelid),w,h,w)
  File "C:\StableDiffusion\stable-diffusion-webui\extensions\sd-webui-supermerger\scripts\mergers\mergers.py", line 579, in draw_origin
    fnt = get_font(fontsize)
  File "C:\StableDiffusion\stable-diffusion-webui\extensions\sd-webui-supermerger\scripts\mergers\mergers.py", line 574, in get_font
    return ImageFont.truetype('javascript/roboto.ttf', fontsize)
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\PIL\ImageFont.py", line 996, in truetype
    return freetype(font)
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\PIL\ImageFont.py", line 993, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "C:\StableDiffusion\stable-diffusion-webui\venv\lib\site-packages\PIL\ImageFont.py", line 248, in __init__
    self.font = core.getfont(
OSError: cannot open resource

朝霧ちしゃさんの記事にもあるようにフォント取得周りのエラーのようなので該当箇所を書き換えて行きましょう

対策

エラー内容から1.3でフォントの取得周りが変更されたことが原因のようなのでmergers.pyの書き換えを行います
エラー内容に合わせてscripts/mergers/にあるmergers.pyをメモ帳などで開き563行目にある

   def get_font(fontsize):
        try:
            from fonts.ttf import Roboto
            try:
                return ImageFont.truetype(opts.font or Roboto, fontsize)
            except Exception:
                return ImageFont.truetype(Roboto, fontsize)

これを

def get_font(fontsize):
    try:
        from modules.paths_internal import roboto_ttf_file
        try:
            return ImageFont.truetype(opts.font or roboto_ttf_file, fontsize)
        except Exception:
            return ImageFont.truetype(roboto_ttf_file, fontsize)

に書き換えることで取り敢えず動作するようになりました

最後に

今回の対策はあくまで応急処置的なものです

いいなと思ったら応援しよう!