Reputation: 11
I'm trying to use the fine tuning method for stable diffusion to generate AI art ths is the google colab link if required https://colab.research.google.com/drive/1yGiI2TYkFMuETm4Rh5bh3-k6yY1C38w0?usp=sharing#scrollTo=60jVYSk0BGC8&uniqifier=3
#@title Setup and check the images you have just added
import requests
import glob
from io import BytesIO
def download_image(url):
try:
response = requests.get(url)
except:
return None
return image.open(BytesIO(response.content)).convert("RGB")
images = list(filter(None,[download_image(url) for url in urls]))
save_path = "./my_concept"
if not os.path.exists(save_path):
os.mkdir(save_path)
[image.save(f"{save_path}/{i}.jpeg") for i, image in enumerate(images)]
image_grid(images, 1, len(images))
returns error
NameError Traceback (most recent call last)
<ipython-input-49-adadff211ef8> in <module>
11 return image.open(BytesIO(response.content)).convert("RGB")
12
---> 13 images = list(filter(None,[download_image(url) for url in urls]))
14 save_path = "./my_concept"
15 if not os.path.exists(save_path):
1 frames
<ipython-input-49-adadff211ef8> in download_image(url)
9 except:
10 return None
---> 11 return image.open(BytesIO(response.content)).convert("RGB")
12
13 images = list(filter(None,[download_image(url) for url in urls]))
NameError: name 'image' is not defined
Upvotes: 1
Views: 1175
Reputation: 11
There are a few issues with the code that need to be fixed. First, the download_image function uses the image.open method to open the image, but it should use the Image.open method instead. This is a typo that needs to be corrected.
Second, the image_grid function is not defined in the code, so calling it will result in an error. This function is used to display the images that were downloaded, but it is not provided in the code. To fix this issue, you would need to define the image_grid function or use a different method to display the images.
Third, the code uses the .jpeg extension for the image files, but the Image.save method uses the format specified by the format parameter to determine the file format. If you want to save the images in JPEG format, you would need to specify the format="JPEG" parameter when calling Image.save.
To fix these issues and improve the code, you can make the following changes:
import requests
import glob
from io import BytesIO
from PIL import Image
def download_image(url):
try:
response = requests.get(url)
except:
return None
return Image.open(BytesIO(response.content)).convert("RGB")
images = list(filter(None,[download_image(url) for url in urls]))
save_path = "./my_concept"
if not os.path.exists(save_path):
os.mkdir(save_path)
# Use a different method to display the images, such as matplotlib
# image_grid(images, 1, len(images))
# Save the images in JPEG format
for i, image in enumerate(images):
image.save(f"{save_path}/{i}.jpeg", format="JPEG")```
Upvotes: 1
Reputation: 21
It's from PIL and make sure the function is imported with \Image.
from PIL import Image
Upvotes: 0