jhj0517
commited on
Commit
·
4cfbecc
1
Parent(s):
7675520
Add helper function
Browse files
modules/live_portrait/live_portrait_inferencer.py
CHANGED
|
@@ -550,6 +550,9 @@ class LivePortraitInferencer:
|
|
| 550 |
# source_image_np = (source_image * 255).byte().numpy()
|
| 551 |
# img_rgb = source_image_np[0]
|
| 552 |
# print("Prepare source...")
|
|
|
|
|
|
|
|
|
|
| 553 |
if len(source_image.shape) <= 3:
|
| 554 |
source_image = source_image[np.newaxis, ...]
|
| 555 |
|
|
|
|
| 550 |
# source_image_np = (source_image * 255).byte().numpy()
|
| 551 |
# img_rgb = source_image_np[0]
|
| 552 |
# print("Prepare source...")
|
| 553 |
+
if isinstance(source_image, str):
|
| 554 |
+
source_image = image_path_to_array(source_image)
|
| 555 |
+
|
| 556 |
if len(source_image.shape) <= 3:
|
| 557 |
source_image = source_image[np.newaxis, ...]
|
| 558 |
|
modules/utils/image_helper.py
CHANGED
|
@@ -56,3 +56,12 @@ def calc_crop_limit(center, img_size, crop_size):
|
|
| 56 |
def save_image(numpy_array: np.ndarray, output_path: str):
|
| 57 |
out = Image.fromarray(numpy_array)
|
| 58 |
out.save(output_path, compress_level=1, format="png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
def save_image(numpy_array: np.ndarray, output_path: str):
|
| 57 |
out = Image.fromarray(numpy_array)
|
| 58 |
out.save(output_path, compress_level=1, format="png")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def image_path_to_array(image_path: str) -> np.ndarray:
|
| 62 |
+
image = Image.open(image_path)
|
| 63 |
+
image_array = np.array(image)
|
| 64 |
+
if len(image_array.shape) <= 3:
|
| 65 |
+
image_array = image_array[np.newaxis, ...]
|
| 66 |
+
|
| 67 |
+
return image_array
|