ginipick commited on
Commit
ba28a5e
·
verified ·
1 Parent(s): 4e85abe

Delete fashion.cod

Browse files
Files changed (1) hide show
  1. fashion.cod +0 -273
fashion.cod DELETED
@@ -1,273 +0,0 @@
1
- import spaces
2
-
3
- import gradio as gr
4
- import os
5
- from pathlib import Path
6
- import sys
7
- import torch
8
- from PIL import Image, ImageOps
9
-
10
- from utils_ootd import get_mask_location
11
-
12
- PROJECT_ROOT = Path(__file__).absolute().parents[1].absolute()
13
- sys.path.insert(0, str(PROJECT_ROOT))
14
-
15
- from preprocess.openpose.run_openpose import OpenPose
16
- from preprocess.humanparsing.run_parsing import Parsing
17
- from ootd.inference_ootd_hd import OOTDiffusionHD
18
- from ootd.inference_ootd_dc import OOTDiffusionDC
19
-
20
-
21
- openpose_model_hd = OpenPose(0)
22
- parsing_model_hd = Parsing(0)
23
- ootd_model_hd = OOTDiffusionHD(0)
24
-
25
- openpose_model_dc = OpenPose(1)
26
- parsing_model_dc = Parsing(1)
27
- ootd_model_dc = OOTDiffusionDC(1)
28
-
29
-
30
- category_dict = ['upperbody', 'lowerbody', 'dress']
31
- category_dict_utils = ['upper_body', 'lower_body', 'dresses']
32
-
33
-
34
- example_path = os.path.join(os.path.dirname(__file__), 'examples')
35
- model_hd = os.path.join(example_path, 'model/model_1.png')
36
- garment_hd = os.path.join(example_path, 'garment/03244_00.jpg')
37
- model_dc = os.path.join(example_path, 'model/model_8.png')
38
- garment_dc = os.path.join(example_path, 'garment/048554_1.jpg')
39
-
40
-
41
- @spaces.GPU
42
- def process_hd(vton_img, garm_img, n_samples, n_steps, image_scale, seed):
43
- model_type = 'hd'
44
- category = 0 # 0:upperbody; 1:lowerbody; 2:dress
45
-
46
- with torch.no_grad():
47
- openpose_model_hd.preprocessor.body_estimation.model.to('cuda')
48
- ootd_model_hd.pipe.to('cuda')
49
- ootd_model_hd.image_encoder.to('cuda')
50
- ootd_model_hd.text_encoder.to('cuda')
51
-
52
- garm_img = Image.open(garm_img).resize((768, 1024))
53
- vton_img = Image.open(vton_img).resize((768, 1024))
54
- keypoints = openpose_model_hd(vton_img.resize((384, 512)))
55
- model_parse, _ = parsing_model_hd(vton_img.resize((384, 512)))
56
-
57
- mask, mask_gray = get_mask_location(model_type, category_dict_utils[category], model_parse, keypoints)
58
- mask = mask.resize((768, 1024), Image.NEAREST)
59
- mask_gray = mask_gray.resize((768, 1024), Image.NEAREST)
60
-
61
- masked_vton_img = Image.composite(mask_gray, vton_img, mask)
62
-
63
- images = ootd_model_hd(
64
- model_type=model_type,
65
- category=category_dict[category],
66
- image_garm=garm_img,
67
- image_vton=masked_vton_img,
68
- mask=mask,
69
- image_ori=vton_img,
70
- num_samples=n_samples,
71
- num_steps=n_steps,
72
- image_scale=image_scale,
73
- seed=seed,
74
- )
75
-
76
- return images
77
-
78
- @spaces.GPU
79
- def process_dc(vton_img, garm_img, category, n_samples, n_steps, image_scale, seed):
80
- model_type = 'dc'
81
- if category == 'Upper-body':
82
- category = 0
83
- elif category == 'Lower-body':
84
- category = 1
85
- else:
86
- category =2
87
-
88
- with torch.no_grad():
89
- openpose_model_dc.preprocessor.body_estimation.model.to('cuda')
90
- ootd_model_dc.pipe.to('cuda')
91
- ootd_model_dc.image_encoder.to('cuda')
92
- ootd_model_dc.text_encoder.to('cuda')
93
-
94
- garm_img = Image.open(garm_img).resize((768, 1024))
95
- vton_img = Image.open(vton_img).resize((768, 1024))
96
- keypoints = openpose_model_dc(vton_img.resize((384, 512)))
97
- model_parse, _ = parsing_model_dc(vton_img.resize((384, 512)))
98
-
99
- mask, mask_gray = get_mask_location(model_type, category_dict_utils[category], model_parse, keypoints)
100
- mask = mask.resize((768, 1024), Image.NEAREST)
101
- mask_gray = mask_gray.resize((768, 1024), Image.NEAREST)
102
-
103
- masked_vton_img = Image.composite(mask_gray, vton_img, mask)
104
-
105
- images = ootd_model_dc(
106
- model_type=model_type,
107
- category=category_dict[category],
108
- image_garm=garm_img,
109
- image_vton=masked_vton_img,
110
- mask=mask,
111
- image_ori=vton_img,
112
- num_samples=n_samples,
113
- num_steps=n_steps,
114
- image_scale=image_scale,
115
- seed=seed,
116
- )
117
-
118
- return images
119
-
120
-
121
- block = gr.Blocks(theme="Nymbo/Nymbo_Theme").queue()
122
- with block:
123
-
124
- with gr.Row():
125
- gr.Markdown("## Half-body")
126
- with gr.Row():
127
- gr.Markdown("***Support upper-body garments***")
128
- with gr.Row():
129
- with gr.Column():
130
- vton_img = gr.Image(label="Model", sources='upload', type="filepath", height=384, value=model_hd)
131
- example = gr.Examples(
132
- inputs=vton_img,
133
- examples_per_page=14,
134
- examples=[
135
- os.path.join(example_path, 'model/model_1.png'),
136
- os.path.join(example_path, 'model/model_2.png'),
137
- os.path.join(example_path, 'model/model_3.png'),
138
- os.path.join(example_path, 'model/model_4.png'),
139
- os.path.join(example_path, 'model/model_5.png'),
140
- os.path.join(example_path, 'model/model_6.png'),
141
- os.path.join(example_path, 'model/model_7.png'),
142
- os.path.join(example_path, 'model/01008_00.jpg'),
143
- os.path.join(example_path, 'model/07966_00.jpg'),
144
- os.path.join(example_path, 'model/05997_00.jpg'),
145
- os.path.join(example_path, 'model/02849_00.jpg'),
146
- os.path.join(example_path, 'model/14627_00.jpg'),
147
- os.path.join(example_path, 'model/09597_00.jpg'),
148
- os.path.join(example_path, 'model/01861_00.jpg'),
149
- ])
150
- with gr.Column():
151
- garm_img = gr.Image(label="Garment", sources='upload', type="filepath", height=384, value=garment_hd)
152
- example = gr.Examples(
153
- inputs=garm_img,
154
- examples_per_page=14,
155
- examples=[
156
- os.path.join(example_path, 'garment/03244_00.jpg'),
157
- os.path.join(example_path, 'garment/00126_00.jpg'),
158
- os.path.join(example_path, 'garment/03032_00.jpg'),
159
- os.path.join(example_path, 'garment/06123_00.jpg'),
160
- os.path.join(example_path, 'garment/02305_00.jpg'),
161
- os.path.join(example_path, 'garment/00055_00.jpg'),
162
- os.path.join(example_path, 'garment/00470_00.jpg'),
163
- os.path.join(example_path, 'garment/02015_00.jpg'),
164
- os.path.join(example_path, 'garment/10297_00.jpg'),
165
- os.path.join(example_path, 'garment/07382_00.jpg'),
166
- os.path.join(example_path, 'garment/07764_00.jpg'),
167
- os.path.join(example_path, 'garment/00151_00.jpg'),
168
- os.path.join(example_path, 'garment/12562_00.jpg'),
169
- os.path.join(example_path, 'garment/04825_00.jpg'),
170
- ])
171
- with gr.Column():
172
- result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True, scale=1)
173
- with gr.Column():
174
- run_button = gr.Button(value="Run")
175
- n_samples = gr.Slider(label="Images", minimum=1, maximum=4, value=1, step=1)
176
- n_steps = gr.Slider(label="Steps", minimum=20, maximum=40, value=20, step=1)
177
- # scale = gr.Slider(label="Scale", minimum=1.0, maximum=12.0, value=5.0, step=0.1)
178
- image_scale = gr.Slider(label="Guidance scale", minimum=1.0, maximum=5.0, value=2.0, step=0.1)
179
- seed = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, value=-1)
180
-
181
- ips = [vton_img, garm_img, n_samples, n_steps, image_scale, seed]
182
- run_button.click(fn=process_hd, inputs=ips, outputs=[result_gallery])
183
-
184
-
185
- with gr.Row():
186
- gr.Markdown("## Full-body")
187
- with gr.Row():
188
- gr.Markdown("***Support upper-body/lower-body/dresses; garment category must be paired!!!***")
189
- with gr.Row():
190
- with gr.Column():
191
- vton_img_dc = gr.Image(label="Model", sources='upload', type="filepath", height=384, value=model_dc)
192
- example = gr.Examples(
193
- label="Examples (upper-body/lower-body)",
194
- inputs=vton_img_dc,
195
- examples_per_page=7,
196
- examples=[
197
- os.path.join(example_path, 'model/model_8.png'),
198
- os.path.join(example_path, 'model/049447_0.jpg'),
199
- os.path.join(example_path, 'model/049713_0.jpg'),
200
- os.path.join(example_path, 'model/051482_0.jpg'),
201
- os.path.join(example_path, 'model/051918_0.jpg'),
202
- os.path.join(example_path, 'model/051962_0.jpg'),
203
- os.path.join(example_path, 'model/049205_0.jpg'),
204
- ])
205
- example = gr.Examples(
206
- label="Examples (dress)",
207
- inputs=vton_img_dc,
208
- examples_per_page=7,
209
- examples=[
210
- os.path.join(example_path, 'model/model_9.png'),
211
- os.path.join(example_path, 'model/052767_0.jpg'),
212
- os.path.join(example_path, 'model/052472_0.jpg'),
213
- os.path.join(example_path, 'model/053514_0.jpg'),
214
- os.path.join(example_path, 'model/053228_0.jpg'),
215
- os.path.join(example_path, 'model/052964_0.jpg'),
216
- os.path.join(example_path, 'model/053700_0.jpg'),
217
- ])
218
- with gr.Column():
219
- garm_img_dc = gr.Image(label="Garment", sources='upload', type="filepath", height=384, value=garment_dc)
220
- category_dc = gr.Dropdown(label="Garment category (important option!!!)", choices=["Upper-body", "Lower-body", "Dress"], value="Upper-body")
221
- example = gr.Examples(
222
- label="Examples (upper-body)",
223
- inputs=garm_img_dc,
224
- examples_per_page=7,
225
- examples=[
226
- os.path.join(example_path, 'garment/048554_1.jpg'),
227
- os.path.join(example_path, 'garment/049920_1.jpg'),
228
- os.path.join(example_path, 'garment/049965_1.jpg'),
229
- os.path.join(example_path, 'garment/049949_1.jpg'),
230
- os.path.join(example_path, 'garment/050181_1.jpg'),
231
- os.path.join(example_path, 'garment/049805_1.jpg'),
232
- os.path.join(example_path, 'garment/050105_1.jpg'),
233
- ])
234
- example = gr.Examples(
235
- label="Examples (lower-body)",
236
- inputs=garm_img_dc,
237
- examples_per_page=7,
238
- examples=[
239
- os.path.join(example_path, 'garment/051827_1.jpg'),
240
- os.path.join(example_path, 'garment/051946_1.jpg'),
241
- os.path.join(example_path, 'garment/051473_1.jpg'),
242
- os.path.join(example_path, 'garment/051515_1.jpg'),
243
- os.path.join(example_path, 'garment/051517_1.jpg'),
244
- os.path.join(example_path, 'garment/051988_1.jpg'),
245
- os.path.join(example_path, 'garment/051412_1.jpg'),
246
- ])
247
- example = gr.Examples(
248
- label="Examples (dress)",
249
- inputs=garm_img_dc,
250
- examples_per_page=7,
251
- examples=[
252
- os.path.join(example_path, 'garment/053290_1.jpg'),
253
- os.path.join(example_path, 'garment/053744_1.jpg'),
254
- os.path.join(example_path, 'garment/053742_1.jpg'),
255
- os.path.join(example_path, 'garment/053786_1.jpg'),
256
- os.path.join(example_path, 'garment/053790_1.jpg'),
257
- os.path.join(example_path, 'garment/053319_1.jpg'),
258
- os.path.join(example_path, 'garment/052234_1.jpg'),
259
- ])
260
- with gr.Column():
261
- result_gallery_dc = gr.Gallery(label='Output', show_label=False, elem_id="gallery", preview=True, scale=1)
262
- with gr.Column():
263
- run_button_dc = gr.Button(value="Run")
264
- n_samples_dc = gr.Slider(label="Images", minimum=1, maximum=4, value=1, step=1)
265
- n_steps_dc = gr.Slider(label="Steps", minimum=20, maximum=40, value=20, step=1)
266
- # scale_dc = gr.Slider(label="Scale", minimum=1.0, maximum=12.0, value=5.0, step=0.1)
267
- image_scale_dc = gr.Slider(label="Guidance scale", minimum=1.0, maximum=5.0, value=2.0, step=0.1)
268
- seed_dc = gr.Slider(label="Seed", minimum=-1, maximum=2147483647, step=1, value=-1)
269
-
270
- ips_dc = [vton_img_dc, garm_img_dc, category_dc, n_samples_dc, n_steps_dc, image_scale_dc, seed_dc]
271
- run_button_dc.click(fn=process_dc, inputs=ips_dc, outputs=[result_gallery_dc])
272
-
273
- block.launch()