Masaaki Kawata
commited on
Commit
Β·
34422ec
1
Parent(s):
9423a8c
Update parallax.py
Browse files- parallax.py +6 -4
parallax.py
CHANGED
|
@@ -13,7 +13,6 @@ load_dotenv(verbose=False)
|
|
| 13 |
|
| 14 |
DEPTH_ANYTHING = DepthAnythingV2(**{'encoder': 'vitl', 'features': 256, 'out_channels': [256, 512, 1024, 1024]})
|
| 15 |
DEPTH_ANYTHING.load_state_dict(torch.load(hf_hub_download(repo_id='depth-anything/Depth-Anything-V2-Large', filename='depth_anything_v2_vitl.pth', repo_type='model', token=os.environ['HF_TOKEN']), map_location='cpu'))
|
| 16 |
-
DEPTH_ANYTHING = DEPTH_ANYTHING.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').eval()
|
| 17 |
HAND_YOLO = YOLO(hf_hub_download('Bingsu/adetailer', 'hand_yolov8n.pt', token=os.environ['HF_TOKEN']))
|
| 18 |
PERSON_YOLO = YOLO(hf_hub_download('Bingsu/adetailer', 'person_yolov8n-seg.pt', token=os.environ['HF_TOKEN']))
|
| 19 |
LAMA = None
|
|
@@ -233,6 +232,8 @@ def feather(image: Image.Image, gauss_radius=1, band_px=1, strength=1.0) -> Imag
|
|
| 233 |
|
| 234 |
|
| 235 |
def generate_parallax_images(image, n_layers=5, maximum=2048):
|
|
|
|
|
|
|
| 236 |
rgb_image = resize_iamge(image.convert('RGB'), maximum)
|
| 237 |
width, height = rgb_image.size
|
| 238 |
rgb = np.asarray(rgb_image)
|
|
@@ -240,7 +241,8 @@ def generate_parallax_images(image, n_layers=5, maximum=2048):
|
|
| 240 |
if LAMA is None:
|
| 241 |
LAMA = SimpleLama(device='cuda' if torch.cuda.is_available() else 'cpu')
|
| 242 |
|
| 243 |
-
|
|
|
|
| 244 |
|
| 245 |
n_clusters = n_layers
|
| 246 |
x = depth.reshape(-1, 1)
|
|
@@ -269,8 +271,8 @@ def generate_parallax_images(image, n_layers=5, maximum=2048):
|
|
| 269 |
|
| 270 |
inpaint_mask = np.zeros_like(front_mask, dtype=bool)
|
| 271 |
|
| 272 |
-
person_results = PERSON_YOLO.predict(source=rgb, conf=0.5, iou=0.45, verbose=False)
|
| 273 |
-
hand_results = HAND_YOLO.predict(source=rgb, conf=0.5, iou=0.45, verbose=False)
|
| 274 |
person_boxes = []
|
| 275 |
hand_boxes = []
|
| 276 |
|
|
|
|
| 13 |
|
| 14 |
DEPTH_ANYTHING = DepthAnythingV2(**{'encoder': 'vitl', 'features': 256, 'out_channels': [256, 512, 1024, 1024]})
|
| 15 |
DEPTH_ANYTHING.load_state_dict(torch.load(hf_hub_download(repo_id='depth-anything/Depth-Anything-V2-Large', filename='depth_anything_v2_vitl.pth', repo_type='model', token=os.environ['HF_TOKEN']), map_location='cpu'))
|
|
|
|
| 16 |
HAND_YOLO = YOLO(hf_hub_download('Bingsu/adetailer', 'hand_yolov8n.pt', token=os.environ['HF_TOKEN']))
|
| 17 |
PERSON_YOLO = YOLO(hf_hub_download('Bingsu/adetailer', 'person_yolov8n-seg.pt', token=os.environ['HF_TOKEN']))
|
| 18 |
LAMA = None
|
|
|
|
| 232 |
|
| 233 |
|
| 234 |
def generate_parallax_images(image, n_layers=5, maximum=2048):
|
| 235 |
+
global LAMA
|
| 236 |
+
|
| 237 |
rgb_image = resize_iamge(image.convert('RGB'), maximum)
|
| 238 |
width, height = rgb_image.size
|
| 239 |
rgb = np.asarray(rgb_image)
|
|
|
|
| 241 |
if LAMA is None:
|
| 242 |
LAMA = SimpleLama(device='cuda' if torch.cuda.is_available() else 'cpu')
|
| 243 |
|
| 244 |
+
depth_anything = DEPTH_ANYTHING.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').eval()
|
| 245 |
+
depth = depth_anything.infer_image(rgb[:, :, ::-1])
|
| 246 |
|
| 247 |
n_clusters = n_layers
|
| 248 |
x = depth.reshape(-1, 1)
|
|
|
|
| 271 |
|
| 272 |
inpaint_mask = np.zeros_like(front_mask, dtype=bool)
|
| 273 |
|
| 274 |
+
person_results = PERSON_YOLO.predict(source=rgb, conf=0.5, iou=0.45, verbose=False, device='0' if torch.cuda.is_available() else 'cpu')
|
| 275 |
+
hand_results = HAND_YOLO.predict(source=rgb, conf=0.5, iou=0.45, verbose=False, device='0' if torch.cuda.is_available() else 'cpu')
|
| 276 |
person_boxes = []
|
| 277 |
hand_boxes = []
|
| 278 |
|