How to move the image generation AI 'Stable Diffusion' with Google Colaboratory and save the image to Google Drive



The image generation AI ``

Stable Diffusion '', which was released to the public on August 23, 2022, generates an image that looks like a picture or photo drawn by a person along the input character string. If you actually use it, you need a machine with NVIDIA GPU, and some knowledge is required for installation, but if you use the Python execution environment ' Google Colaboratory ' provided by Google, you can use a low-spec notebook PC. But it is possible to move with Stable Diffusion for free. However, the free version disconnects the runtime after a certain amount of time, but the images generated on Google Colaboratory are only temporary, so if they are not saved locally, the generated images will disappear. Therefore, I tried to automatically save the image to Google Drive by mounting Google Drive on Google Colaboratory and specifying the image output destination as the Google Drive folder.

Stable Diffusion with ???? Diffusers
https://huggingface.co/blog/stable_diffusion

The procedure for running Stable Diffusion on Google Colaboratory is summarized in detail in the following article.

Summary of how to use image generation AI ``Stable Diffusion'' even on low-spec PCs for free and without waiting time - GIGAZINE



First, look at the above article and enter ' pipe.to('cuda') ' to proceed to the point where Stable Diffusion is ready.



Next, mount Google Drive. Click the folder icon on the left, then click the Google Drive icon.



The command to mount Google Drive is automatically entered, so click the play icon to execute it.



You will be asked if you want to allow this notebook to access Google Drive files, so click 'Connect to Google Drive'.



Since the login screen pops up, select an account.



Access to your Google Drive account will be requested, so click 'Allow'.



Then, in the notebook of Google Colaboratory, 'drive/MyDrive' is displayed in the file column in the left column.



This time, I created a folder called 'AI Image' in Google Drive as a folder for saving images generated by Stable Diffusion.



This time, specify the created 'AI Image' as the output destination. The commands are as follows.

[code] import os
os.chdir('/content/drive/MyDrive/AI Image')[/code]

Enter the command in your notebook and click the play icon. Now you are ready.



After that, enter the character string and generate the image. The character string this time is 'cat eat ramen midnight at stall, in Renoir style, perfect lighting' and will be output as 'cat.png'.



When I looked at 'AI Image' in Google Drive after the output was finished, the output 'cat.png' was saved.



The output image is below. I had a Renoir -style drawing of a cat eating ramen. The cat is drawn in a relatively good way, but the cat is supposed to be the side that eats ramen, but for some reason it is the side that can be eaten as a ramen ingredient, resulting in a somewhat bizarre result.

in Review,   Web Service,   Art, Posted by log1i_yk