herrDeng網內搜尋

自訂搜尋

Ads

2023年10月16日 星期一

AI人工智慧python試作Keras CV實作之Stable Diffusion


iPython code在此
print('試試stable diffusion')
print('參閱https://keras.io/api/keras_cv/models/stable_diffusion/')

Linux指令
!cat /etc/os-release

!nvidia-smi

!python --version

安裝keras-cv,匯入套件
!pip install --upgrade keras-cv

from keras_cv.models import StableDiffusion
from PIL import Image
產生假圖
model = StableDiffusion(img_height=512, img_width=512 ,jit_compile=True)

img = model.text_to_image(
    prompt="cute magical flying black shiba inu, fantasy art,"
    "high quality, highly detailed, elegant, sharp focus,"
    "concept art, character concepts, digital painting, mystery, adventure",
    batch_size=3,  # How many images to generate at once
    num_steps=25,  # Number of iterations (controls image quality)
  #  seed=123,  # Set this to always get the same image from the same prompt
)
轉成圖檔,秀圖,下載假圖
for i in range(3):
  Image.fromarray(img[i]).save(str(i)+"shiba.png")
  print(f"saved at {i}shiba.png")

from google.colab.patches import cv2_imshow
import cv2

for i in range(3):
  im=cv2.imread(str(i)+'shiba.png')
  cv2_imshow(im)

from google.colab import files
for i in range(3):
  files.download(str(i)+'shiba.png')

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章