JUNGU commited on
Commit
18fd32d
ยท
1 Parent(s): f60a5d4

Delete stable_diffusion_4kids.py

Browse files
Files changed (1) hide show
  1. stable_diffusion_4kids.py +0 -130
stable_diffusion_4kids.py DELETED
@@ -1,130 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """Stable Diffusion์ง์ ‘ ๋งŒ๋“ค์–ด๋ณด๊ธฐ
3
-
4
- Automatically generated by Colaboratory.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1IjcI8U0touR68J6aS2n7Ko97vQSPnGzm
8
-
9
- # ์ดˆ๋“ฑํ•™์ƒ๋“ค๋„ ๋”ฐ๋ผํ•  ์ˆ˜ ์žˆ๋Š” ์ธ๊ณต์ง€๋Šฅ ์ด๋ฏธ์ง€ ๋งŒ๋“ค๊ธฐ
10
- # Stable Diffusion ์ง์ ‘ ๋งŒ๋“ค์–ด๋ณด๊ธฐ
11
- > ์œ ํŠœ๋ธŒ [์ฝ”๋‚œ์ŒคTV](https://www.youtube.com/@conanssam)
12
-
13
- > ์ฐธ๊ณ : ์œ ํŠœ๋ธŒ [๋นตํ˜•์˜ ๊ฐœ๋ฐœ๋„์ƒ๊ตญ](https://www.youtube.com/@bbanghyong)
14
-
15
- > [์ฐธ๊ณ ๋ชจ๋ธ](https://keras.io/guides/keras_cv/generate_images_with_stable_diffusion/)
16
- https://keras.io/guides/keras_cv/generate_images_with_stable_diffusion/
17
-
18
- ```
19
- @misc{wood2022kerascv,
20
- title={KerasCV},
21
- author={Wood, Luke and Tan, Zhenyu and Ian, Stenbit and Zhu, Scott and Chollet, Fran\c{c}ois and others},
22
- year={2022},
23
- howpublished={\url{https://github.com/keras-team/keras-cv}},
24
- }
25
- ```
26
-
27
- # ํ• ๋‹น๋œ GPU(๊ทธ๋ž˜ํ”ฝ์นด๋“œ)์˜ ์‚ฌ์–‘์„ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
28
- """
29
-
30
- !nvidia-smi
31
-
32
- """# ์ผ€๋ผ์ŠคCV(keras-cv)๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค."""
33
-
34
- !pip install --upgrade keras-cv
35
-
36
- """#๋ชจ๋ธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
37
- > ์‹œ๊ฐ„์ธก์ •์„ ์œ„ํ•ด time
38
-
39
- > ๋ชจ๋ธ์ƒ์„ฑ์„ ์œ„ํ•ด keras_cv๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
40
-
41
- > ํ…์„œํ”Œ๋กœ์šฐ์— ์žˆ๋Š” ์ผ€๋ผ์Šค๋„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
42
-
43
- > ๋งทํ”Œ๋กฏ๋ฆฝ์•ˆ์—์„œ ํŒŒ์ดํ”Œ๋กฏ์„ ๊ฐ€์ ธ์™€ ๊ทธ๋ž˜ํ”„๋ฅผ ๊ทธ๋ฆฝ๋‹ˆ๋‹ค.
44
- """
45
-
46
- import time
47
- import keras_cv
48
- from tensorflow import keras
49
- import matplotlib.pyplot as plt
50
-
51
- """## Stable Diffusion ๋ชจ๋ธ ๋กœ๋“œ(5๋ถ„์ •๋„ ์†Œ์š”)
52
- > keras_cv์•ˆ์— ๋ชจ๋ธ๋“ค ์•ˆ์— ์ž‡๋Š” ์Šคํ…Œ์ด๋ธ” ๋””ํ“จ์ „์„ ๊บผ๋‚ด์ค๋‹ˆ๋‹ค.
53
-
54
- > ์ด๋ฏธ์ง€ ํญ๊ณผ ํฌ๊ธฐ๋Š” 512๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
55
-
56
- > ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ํฌ๊ฒŒ ํ•  ๊ฒฝ์šฐ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ถ€์กฑํ•ด ์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
57
-
58
- > ์ด๋ฏธ์ง€ ํฌ๊ธฐ๋ฅผ ์ค„์ผ ๊ฒฝ์šฐ ์‚ฌ์ง„ ํ€„๋ฆฌํ‹ฐ๊ฐ€ ๋–จ์–ด์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
59
- """
60
-
61
- keras.mixed_precision.set_global_policy("mixed_float16")
62
- model = keras_cv.models.StableDiffusion(img_height=512, img_width=512, jit_compile=True)
63
-
64
- """plot_image๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ธ์ž๋กœ ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด ์•Œ์•„์„œ ์ด๋ฏธ์ง€๋ฅผ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.
65
-
66
- len์€ ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค.
67
- plt.subplot์„ ์ด์šฉํ•ด์„œ ์ด๋ฏธ์ง€์˜ ํฌ๊ธฐ์— ๋งž๊ฒŒ ํญ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
68
- >[keras_cv](https://keras.io/guides/keras_cv/generate_images_with_stable_diffusion/)์—์„œ ํ”„๋กฌํ”„ํŠธ ์˜ˆ์ œ๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.
69
- """
70
-
71
- def plot_images(images):
72
- plt.figure(figsize=(10, 10))
73
- for i in range(len(images)):
74
- ax = plt.subplot(1, len(images), i + 1)
75
- plt.imshow(images[i])
76
- plt.axis("off")
77
- plt.tight_layout()
78
-
79
- """## ์ฒซ ๋ฒˆ์งธ ์ด๋ฏธ์ง€ ์ƒ์„ฑ
80
-
81
- > ์šฐ์ฃผ์ธ์ด ๋ง์„ ํƒ€๊ณ  ์žˆ๋Š” ์‚ฌ์ง„
82
- """
83
-
84
- images = model.text_to_image("photograph of an astronaut riding a horse", batch_size=3)
85
-
86
- plot_images(images)
87
-
88
- """## ํ•œ๊ธ€ -> ์˜์–ด ๋ฒˆ์—ญ"""
89
-
90
- !pip install translate
91
-
92
- from translate import Translator
93
-
94
- translator = Translator(from_lang="ko", to_lang="en")
95
-
96
- translation = translator.translate("์œ ํŠœ๋ธŒ๋ฅผ ๋ณด๋Š” ํ•™์ƒ๋“ค")
97
-
98
- translation
99
-
100
- """## ํ•จ์ˆ˜ํ™”"""
101
-
102
- def generate_images(text, n=3):
103
- print(text)
104
- translation = translator.translate(text)
105
- print(translation)
106
-
107
- images = model.text_to_image(translation, batch_size=n)
108
-
109
- return images
110
-
111
- images = generate_images("ํŽญ๊ท„์ด ๊ณฐํ•œํ…Œ ๋ฝ€๋ฝ€ํ•˜๋Š” ๋ชจ์Šต")
112
-
113
- plot_images(images)
114
-
115
- """## ๊ทธ๋ฆผ ์ƒ์„ฑ ์•ฑ ๋งŒ๋“ค๊ธฐ"""
116
-
117
- !pip install -q gradio
118
-
119
- import gradio as gr
120
-
121
- def inference(text):
122
- image = generate_images(text, 1).squeeze()
123
- return image
124
-
125
- demo = gr.Interface(fn=inference, inputs="text", outputs="image")
126
-
127
- demo.launch(share=True)
128
-
129
-
130
-