質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

1回答

2155閲覧

Stable Diffusion(Google colab環境)でのimg2img及びControlNet使用時のPythonエラー解決

kemkemchan

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2023/05/16 12:04

編集2023/05/16 13:46

イメージ説明### 実現したいこと
Stable Diffusion(Google colab環境)でのimg2img及びControlNet使用時のエラー解決

前提

Stable Diffusion Web UIをGoogle colab環境で使用しています。
txt2imgは問題なく動作しているのですが、img2img及びControlNetの場合以下のエラーメッセージが発生して画像生成ができません。

発生している問題・エラーメッセージ

エラーメッセージ AttributeError: 'NoneType' object has no attribute 'to'

該当のソースコード

Python

1#@markdown # Start Stable-Diffusion 2from IPython.utils import capture 3import time 4import sys 5import fileinput 6from pyngrok import ngrok, conf 7 8Use_Cloudflare_Tunnel = False #@param {type:"boolean"} 9#@markdown - Offers better gradio responsivity 10 11Ngrok_token = "" #@param {type:"string"} 12 13#@markdown - Input your ngrok token if you want to use ngrok server 14 15User = "" #@param {type:"string"} 16Password= "" #@param {type:"string"} 17#@markdown - Add credentials to your Gradio interface (optional) 18 19auth=f"--gradio-auth {User}:{Password}" 20if User =="" or Password=="": 21 auth="" 22 23 24with capture.capture_output() as cap: 25 %cd /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/modules/ 26 27 if Use_Latest_Working_Commit: 28 !wget -q -O paths.py https://github.com/TheLastBen/fast-stable-diffusion/raw/5632d2ef7fffd940976538d270854ec4faf26855/AUTOMATIC1111_files/paths.py 29 !wget -q -O extras.py https://github.com/AUTOMATIC1111/stable-diffusion-$blasphemy/raw/a9eab236d7e8afa4d6205127904a385b2c43bb24/modules/extras.py 30 !wget -q -O sd_models.py https://github.com/AUTOMATIC1111/stable-diffusion-$blasphemy/raw/a9eab236d7e8afa4d6205127904a385b2c43bb24/modules/sd_models.py 31 !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://github.com/TheLastBen/fast-stable-diffusion/raw/7ff88eaa1fb4997bacd9845bd487f9a14335d625/AUTOMATIC1111_files/blocks.py 32 else: 33 !wget -q -O paths.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/paths.py 34 !wget -q -O extras.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-$blasphemy/master/modules/extras.py 35 !wget -q -O sd_models.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-$blasphemy/master/modules/sd_models.py 36 !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py 37 %cd /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/ 38 39 !sed -i "s@os.path.splitext(checkpoint_file)@os.path.splitext(checkpoint_file); map_location='cuda'@" /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/modules/sd_models.py 40 !sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/webui.py 41 !sed -i "s@map_location='cpu'@map_location='cuda'@" /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/modules/extras.py 42 !sed -i 's@/content/gdrive/MyDrive/sd/stablediffusion@/content/gdrive/{mainpth}/sd/stablediffusion@' /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/modules/paths.py 43 !sed -i 's@print(\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py 44 !sed -i 's@\"quicksettings\": OptionInfo(.*@"quicksettings": OptionInfo("sd_model_checkpoint, sd_vae, CLIP_stop_at_last_layers, inpainting_mask_weight, initial_noise_multiplier", "Quicksettings list"),@' /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/modules/shared.py 45 46share='' 47if Ngrok_token!="": 48 ngrok.kill() 49 srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url 50 51 for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True): 52 if line.strip().startswith('self.server_name ='): 53 line = f' self.server_name = "{srv[8:]}"\n' 54 if line.strip().startswith('self.protocol = "https"'): 55 line = ' self.protocol = "https"\n' 56 if line.strip().startswith('if self.loc 57 al_url.startswith("https") or self.is_colab'): 58 line = '' 59 if line.strip().startswith('else "http"'): 60 line = '' 61 sys.stdout.write(line) 62 63elif Use_Cloudflare_Tunnel: 64 with capture.capture_output() as cap: 65 !pkill cloudflared 66 time.sleep(4) 67 !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 & 68 time.sleep(4) 69 !grep -o 'https[^[:space:]]*\.trycloudflare.com' /content/srv.txt >/content/srvr.txt 70 time.sleep(2) 71 srv= getoutput('cat /content/srvr.txt') 72 73 for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True): 74 if line.strip().startswith('self.server_name ='): 75 line = f' self.server_name = "{srv[8:]}"\n' 76 if line.strip().startswith('self.protocol = "https"'): 77 line = ' self.protocol = "https"\n' 78 if line.strip().startswith('if self.local_url.startswith("https") or self.is_colab'): 79 line = '' 80 if line.strip().startswith('else "http"'): 81 line = '' 82 sys.stdout.write(line) 83 84 !rm /content/srv.txt /content/srvr.txt 85 86else: 87 share='--share' 88 89try: 90 model 91 if os.path.isfile(model): 92 !python /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt "$model" --opt-sdp-attention $auth --disable-console-progressbars 93 else: 94 !python /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir "$model" --opt-sdp-attention $auth --disable-console-progressbars 95except: 96 !python /content/gdrive/$mainpth/sd/stable-diffusion-$blasphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --opt-sdp-attention $auth --disable-console-progressbars

試したこと

補足情報(FW/ツールのバージョンなど)

非エンジニアでYoutube動画を見ながら設定したので具体的なコードの中身がわかりませんが、多少のプログラミング知識はあります。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

meg_

2023/05/16 12:24

> エラーメッセージ > AttributeError: 'NoneType' object has no attribute 'to' 上記エラーはどの箇所で発生したものでしょうか?
kemkemchan

2023/05/16 13:12 編集

生成された画像が表示される部分の下にあるフォルダアイコンや"SAVE"ボタンなどがある列の下の部分になります。 追記:「Traceback」とは書かれておらず"AttributeError: 'NoneType' object has no attribute 'to'"が表示されています。
jbpb0

2023/05/16 13:07

質問に記載のエラーメッセージよりも上に「Traceback」と書かれてたら、そこから下をできるだけ省略せずに質問に記載してください (ここに書くのではなく、質問を編集して追記する)
meg_

2023/05/16 13:47 編集

> img2img及びControlNetの場合以下のエラーメッセージが発生して画像生成ができません。 Stable Diffusion Web UIをGoogle colabで試しても質問のエラーは発生しないようです。質問のコードは使っていないので、その「非エンジニアでYoutube動画を見ながら設定した」の動画の作成者に質問するのが良いかもですね。
kemkemchan

2023/05/16 13:48

Stable Diffusion Web UIをGoogle colabで実行しています。 実際のエラーがでているスクリーンショットを添付しました。
kemkemchan

2023/05/16 13:50

そうですよね。ありがとうございます。
meg_

2023/05/16 13:50

日本語化されたバージョンなんですね。 画像を入力していないからではないですか?
kemkemchan

2023/05/16 13:52

スクショでは画像は消していますが入力していても同様のエラーとなります。
meg_

2023/05/16 14:00

> スクショでは画像は消していますが入力していても同様のエラーとなります。 そうなんですね。 とりあえず日本語されていない元のを利用するのが回避策でしょうか? ところでコード引用元を明記するべきかと思います。コードにも著作権があります。(転載禁止の場合はそもそもNGになりますが) またそのYouTube動画のコメント欄では他の方はエラーなく使えている様子でしょうか?
kemkemchan

2023/05/16 14:02

>ところでコード引用元を明記するべきかと思います。コードにも著作権があります。 大変失礼しました。知識不足で申し訳ないです。 >またそのYouTube動画のコメント欄では他の方はエラーなく使えている様子でしょうか? 同様のエラー報告はありませんでした。
kemkemchan

2023/05/17 13:02

>とりあえず日本語されていない元のを利用するのが回避策でしょうか? 日本語化パッチを削除しましたが、変化はありませんでした。
guest

回答1

0

質問のエラーの解消方法ではありませんが、Stable Diffusion WebUIを利用する方法としてはStable Diffusion WebUIとGoogle Colabで無料でAI画像を生成しよう!の方法で出来ました。(2023/5/16現在、Google Colaboratory(ランタイム:GPU)で確認済)

!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui %cd /content/stable-diffusion-webui # Web UIを実行 !python launch.py --share --xformers --enable-insecure-extension-access

動作確認はデフォルトのモデルで実施しました。他のモデル等についてはリンク先などを参照なさってください。

投稿2023/05/17 14:03

meg_

総合スコア10580

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問