Spaces:
Runtime error
Runtime error
lyndonzheng
commited on
Commit
Β·
ae2071d
1
Parent(s):
bffa280
update bugs
Browse files
app.py
CHANGED
|
@@ -38,27 +38,28 @@ def main():
|
|
| 38 |
raise gr.Error("No image uploaded!")
|
| 39 |
|
| 40 |
def preprocess(image, dynamic_size=False, padding=True):
|
| 41 |
-
|
| 42 |
size = 32
|
| 43 |
if dynamic_size:
|
| 44 |
while max(h, w) // size > 20:
|
| 45 |
size *=2
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
model.cfg.dataset.width, model.cfg.dataset.height =
|
| 49 |
-
model.set_backproject()
|
| 50 |
else:
|
| 51 |
model.cfg.dataset.height, model.cfg.dataset.width = 256, 384
|
| 52 |
-
|
| 53 |
image, (model.cfg.dataset.height, model.cfg.dataset.width),
|
| 54 |
interpolation=TT.InterpolationMode.BICUBIC
|
| 55 |
)
|
| 56 |
if padding:
|
| 57 |
-
|
| 58 |
model.cfg.dataset.pad_border_aug = 32
|
| 59 |
else:
|
|
|
|
| 60 |
model.cfg.dataset.pad_border_aug = 0
|
| 61 |
-
|
|
|
|
| 62 |
|
| 63 |
@spaces.GPU()
|
| 64 |
def reconstruct_and_export(image):
|
|
|
|
| 38 |
raise gr.Error("No image uploaded!")
|
| 39 |
|
| 40 |
def preprocess(image, dynamic_size=False, padding=True):
|
| 41 |
+
h, w = image.size
|
| 42 |
size = 32
|
| 43 |
if dynamic_size:
|
| 44 |
while max(h, w) // size > 20:
|
| 45 |
size *=2
|
| 46 |
+
crop_image = TTF.center_crop(image, (w // size * size, h // size * size))
|
| 47 |
+
resize_image = TTF.resize(crop_image, (w // size * 32, h // size * 32), interpolation=TT.InterpolationMode.BICUBIC)
|
| 48 |
+
model.cfg.dataset.width, model.cfg.dataset.height = resize_image.size
|
|
|
|
| 49 |
else:
|
| 50 |
model.cfg.dataset.height, model.cfg.dataset.width = 256, 384
|
| 51 |
+
resize_image = TTF.resize(
|
| 52 |
image, (model.cfg.dataset.height, model.cfg.dataset.width),
|
| 53 |
interpolation=TT.InterpolationMode.BICUBIC
|
| 54 |
)
|
| 55 |
if padding:
|
| 56 |
+
input_image = pad_border_fn(resize_image)
|
| 57 |
model.cfg.dataset.pad_border_aug = 32
|
| 58 |
else:
|
| 59 |
+
input_image = resize_image
|
| 60 |
model.cfg.dataset.pad_border_aug = 0
|
| 61 |
+
model.set_backproject()
|
| 62 |
+
return input_image
|
| 63 |
|
| 64 |
@spaces.GPU()
|
| 65 |
def reconstruct_and_export(image):
|