Spaces:
Running
Running
Update
Browse files
app.py
CHANGED
@@ -20,6 +20,8 @@ DESCRIPTION = '''# Text2Human
|
|
20 |
|
21 |
This is an unofficial demo for <a href="https://github.com/yumingj/Text2Human">https://github.com/yumingj/Text2Human</a>.
|
22 |
You can modify sample steps and seeds. By varying seeds, you can sample different human images under the same pose, shape description, and texture description. The larger the sample steps, the better quality of the generated images. (The default value of sample steps is 256 in the original repo.)
|
|
|
|
|
23 |
'''
|
24 |
FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=hysts.text2human" />'
|
25 |
|
@@ -68,8 +70,7 @@ def main():
|
|
68 |
with gr.Row():
|
69 |
label_image = gr.Image(label='Label Image',
|
70 |
type='numpy',
|
71 |
-
elem_id='label-image'
|
72 |
-
interactive=False)
|
73 |
with gr.Row():
|
74 |
shape_text = gr.Textbox(
|
75 |
label='Shape Description',
|
|
|
20 |
|
21 |
This is an unofficial demo for <a href="https://github.com/yumingj/Text2Human">https://github.com/yumingj/Text2Human</a>.
|
22 |
You can modify sample steps and seeds. By varying seeds, you can sample different human images under the same pose, shape description, and texture description. The larger the sample steps, the better quality of the generated images. (The default value of sample steps is 256 in the original repo.)
|
23 |
+
|
24 |
+
Label image generation step can be skipped. However, in that case, the input label image must be 512x256 in size and must contain only the specified colors.
|
25 |
'''
|
26 |
FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=hysts.text2human" />'
|
27 |
|
|
|
70 |
with gr.Row():
|
71 |
label_image = gr.Image(label='Label Image',
|
72 |
type='numpy',
|
73 |
+
elem_id='label-image')
|
|
|
74 |
with gr.Row():
|
75 |
shape_text = gr.Textbox(
|
76 |
label='Shape Description',
|
model.py
CHANGED
@@ -52,6 +52,7 @@ class Model:
|
|
52 |
self.config['device'] = device
|
53 |
self._download_models()
|
54 |
self.model = SampleFromPoseModel(self.config)
|
|
|
55 |
|
56 |
def _load_config(self) -> dict:
|
57 |
path = 'Text2Human/configs/sample_from_pose.yml'
|
@@ -84,10 +85,13 @@ class Model:
|
|
84 |
|
85 |
@staticmethod
|
86 |
def process_mask(mask: torch.Tensor) -> torch.Tensor:
|
|
|
|
|
87 |
seg_map = np.full(mask.shape[:-1], -1)
|
88 |
for index, color in enumerate(COLOR_LIST):
|
89 |
seg_map[np.sum(mask == color, axis=2) == 3] = index
|
90 |
-
|
|
|
91 |
return seg_map
|
92 |
|
93 |
@staticmethod
|
@@ -124,6 +128,8 @@ class Model:
|
|
124 |
return
|
125 |
mask = label_image.copy()
|
126 |
seg_map = self.process_mask(mask)
|
|
|
|
|
127 |
self.model.segm = torch.from_numpy(seg_map).unsqueeze(0).unsqueeze(
|
128 |
0).to(self.model.device)
|
129 |
self.model.generate_quantized_segm()
|
|
|
52 |
self.config['device'] = device
|
53 |
self._download_models()
|
54 |
self.model = SampleFromPoseModel(self.config)
|
55 |
+
self.model.batch_size = 1
|
56 |
|
57 |
def _load_config(self) -> dict:
|
58 |
path = 'Text2Human/configs/sample_from_pose.yml'
|
|
|
85 |
|
86 |
@staticmethod
|
87 |
def process_mask(mask: torch.Tensor) -> torch.Tensor:
|
88 |
+
if mask.shape != (512, 256, 3):
|
89 |
+
return None
|
90 |
seg_map = np.full(mask.shape[:-1], -1)
|
91 |
for index, color in enumerate(COLOR_LIST):
|
92 |
seg_map[np.sum(mask == color, axis=2) == 3] = index
|
93 |
+
if not (seg_map != -1).all():
|
94 |
+
return None
|
95 |
return seg_map
|
96 |
|
97 |
@staticmethod
|
|
|
128 |
return
|
129 |
mask = label_image.copy()
|
130 |
seg_map = self.process_mask(mask)
|
131 |
+
if seg_map is None:
|
132 |
+
return
|
133 |
self.model.segm = torch.from_numpy(seg_map).unsqueeze(0).unsqueeze(
|
134 |
0).to(self.model.device)
|
135 |
self.model.generate_quantized_segm()
|