init
Browse files- app.py +36 -18
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -3,18 +3,49 @@ import torch
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
import spaces # Import spaces for ZeroGPU compatibility
|
| 6 |
-
from einops import rearrange
|
| 7 |
-
|
| 8 |
import math
|
| 9 |
-
import
|
| 10 |
-
import argparse
|
| 11 |
-
from PIL import Image
|
| 12 |
from einops import rearrange
|
| 13 |
from mmengine.config import Config
|
| 14 |
from xtuner.registry import BUILDER
|
| 15 |
from xtuner.model.utils import guess_load_checkpoint
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
from scripts.camera.cam_dataset import Cam_Generator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
##### load model
|
| 20 |
config = "configs/pipelines/stage_2_base.py"
|
|
@@ -29,19 +60,6 @@ if torch.cuda.is_available():
|
|
| 29 |
else:
|
| 30 |
model = model.to(torch.float32)
|
| 31 |
|
| 32 |
-
def expand2square(pil_img, background_color):
|
| 33 |
-
width, height = pil_img.size
|
| 34 |
-
if width == height:
|
| 35 |
-
return pil_img
|
| 36 |
-
elif width > height:
|
| 37 |
-
result = Image.new(pil_img.mode, (width, width), background_color)
|
| 38 |
-
result.paste(pil_img, (0, (width - height) // 2))
|
| 39 |
-
return result
|
| 40 |
-
else:
|
| 41 |
-
result = Image.new(pil_img.mode, (height, height), background_color)
|
| 42 |
-
result.paste(pil_img, ((height - width) // 2, 0))
|
| 43 |
-
return result
|
| 44 |
-
|
| 45 |
|
| 46 |
@torch.inference_mode()
|
| 47 |
@spaces.GPU(duration=120)
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
import spaces # Import spaces for ZeroGPU compatibility
|
|
|
|
|
|
|
| 6 |
import math
|
| 7 |
+
import re
|
|
|
|
|
|
|
| 8 |
from einops import rearrange
|
| 9 |
from mmengine.config import Config
|
| 10 |
from xtuner.registry import BUILDER
|
| 11 |
from xtuner.model.utils import guess_load_checkpoint
|
| 12 |
|
| 13 |
+
|
| 14 |
+
import matplotlib
|
| 15 |
+
matplotlib.use("Agg")
|
| 16 |
+
import matplotlib.pyplot as plt
|
| 17 |
+
|
| 18 |
from scripts.camera.cam_dataset import Cam_Generator
|
| 19 |
+
from scripts.camera.visualization.visualize_batch import make_perspective_figures
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
NUM = r"[+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:[eE][+-]?\d+)?"
|
| 23 |
+
CAM_PATTERN = re.compile(r"(?:camera parameters.*?:|roll.*?:)\s*("+NUM+r")\s*,\s*("+NUM+r")\s*,\s*("+NUM+r")", re.IGNORECASE|re.DOTALL)
|
| 24 |
+
|
| 25 |
+
def center_crop(image):
|
| 26 |
+
w, h = image.size
|
| 27 |
+
s = min(w, h)
|
| 28 |
+
l = (w - s) // 2
|
| 29 |
+
t = (h - s) // 2
|
| 30 |
+
return image.crop((l, t, l + s, t + s))
|
| 31 |
+
|
| 32 |
+
def preprocess_image(image_path, image_size):
|
| 33 |
+
image = Image.open(image_path).convert('RGB')
|
| 34 |
+
image = center_crop(image)
|
| 35 |
+
image = image.resize((image_size, image_size))
|
| 36 |
+
x = torch.from_numpy(np.array(image)).float()
|
| 37 |
+
x = x / 255.0
|
| 38 |
+
x = 2 * x - 1
|
| 39 |
+
x = rearrange(x, 'h w c -> c h w')
|
| 40 |
+
return x
|
| 41 |
+
|
| 42 |
+
def load_square_rgb(image_path, image_size):
|
| 43 |
+
image = Image.open(image_path).convert('RGB')
|
| 44 |
+
image = center_crop(image)
|
| 45 |
+
image = image.resize((image_size, image_size))
|
| 46 |
+
arr = np.array(image)[:, :, ::-1]
|
| 47 |
+
return arr.copy()
|
| 48 |
+
|
| 49 |
|
| 50 |
##### load model
|
| 51 |
config = "configs/pipelines/stage_2_base.py"
|
|
|
|
| 60 |
else:
|
| 61 |
model = model.to(torch.float32)
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
@torch.inference_mode()
|
| 65 |
@spaces.GPU(duration=120)
|
requirements.txt
CHANGED
|
@@ -22,4 +22,6 @@ transformers-stream-generator==0.0.5
|
|
| 22 |
triton==3.3.0
|
| 23 |
xtuner==0.1.23
|
| 24 |
yarl==1.20.0
|
|
|
|
|
|
|
| 25 |
|
|
|
|
| 22 |
triton==3.3.0
|
| 23 |
xtuner==0.1.23
|
| 24 |
yarl==1.20.0
|
| 25 |
+
deepspeed
|
| 26 |
+
git+https://github.com/KangLiao929/Puffin
|
| 27 |
|