Skip to content

Commit 51f95e3

Browse files
committed
update tensor_to_pil
1 parent 93c076c commit 51f95e3

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

nodes/image_utility.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import os
22
import io
3-
from random import random
4-
from turtle import color
5-
import black
63
import requests
74
import json
85
import numpy as np
@@ -73,13 +70,12 @@ def pil_to_tensor(pil):
7370

7471

7572
def tensor_to_pil(tensor):
76-
# [H, W, C] to [C, H, W]
77-
return toPIL(tensor.permute(2, 0, 1))
78-
79-
80-
def tensor_to_pil_single(tensor):
81-
# [H, W] to [ H, W]
82-
return toPIL(tensor)
73+
if len(tensor.shape) == 2:
74+
# [H, W] to [H, W]
75+
return toPIL(tensor)
76+
else:
77+
# [H, W, C] to [C, H, W]
78+
return toPIL(tensor.permute(2, 0, 1))
8379

8480

8581
def tensor_to_batch(tensor, h, w, c):
@@ -1019,7 +1015,7 @@ def node_function(self, images, masks, fill_color):
10191015
out_images = []
10201016
for image, mask in zip(images, masks):
10211017
pil = tensor_to_pil(image)
1022-
pil_mask = tensor_to_pil_single(1 - mask)
1018+
pil_mask = tensor_to_pil(1 - mask)
10231019

10241020
new_pil = Image.new("RGBA", pil.size, fill_color)
10251021
new_pil.paste(pil, pil_mask)
@@ -1056,25 +1052,25 @@ def node_function(self, metallic, ambient_occlusion, detail_mask, smoothness):
10561052
mask_maps = []
10571053
for metallic_tensor, ambient_occlusion_tensor, detail_mask_tensor, smoothness_tensor in zip(metallic, ambient_occlusion, detail_mask, smoothness):
10581054
if len(metallic_tensor.shape) == 2:
1059-
metallic_pil_single = tensor_to_pil_single(metallic_tensor)
1055+
metallic_pil_single = tensor_to_pil(metallic_tensor)
10601056
metallic_pil = metallic_pil_single.convert("RGB")
10611057
else:
10621058
metallic_pil = tensor_to_pil(metallic_tensor)
10631059

10641060
if len(ambient_occlusion_tensor.shape) == 2:
1065-
ambient_occlusion_pil_single = tensor_to_pil_single(ambient_occlusion_tensor)
1061+
ambient_occlusion_pil_single = tensor_to_pil(ambient_occlusion_tensor)
10661062
ambient_occlusion_pil = ambient_occlusion_pil_single.convert("RGB")
10671063
else:
10681064
ambient_occlusion_pil = tensor_to_pil(ambient_occlusion_tensor)
10691065

10701066
if len(detail_mask_tensor.shape) == 2:
1071-
detail_mask_pil_single = tensor_to_pil_single(detail_mask_tensor)
1067+
detail_mask_pil_single = tensor_to_pil(detail_mask_tensor)
10721068
detail_mask_pil = detail_mask_pil_single.convert("RGB")
10731069
else:
10741070
detail_mask_pil = tensor_to_pil(detail_mask_tensor)
10751071

10761072
if len(smoothness_tensor.shape) == 2:
1077-
smoothness_pil_single = tensor_to_pil_single(smoothness_tensor)
1073+
smoothness_pil_single = tensor_to_pil(smoothness_tensor)
10781074
smoothness_pil = smoothness_pil_single.convert("RGB")
10791075
else:
10801076
smoothness_pil = tensor_to_pil(smoothness_tensor)
@@ -1114,19 +1110,19 @@ def node_function(self, albedo, normal, smoothness):
11141110
detail_maps = []
11151111
for albedo_tensor, normal_tensor, smoothness_tensor in zip(albedo, normal, smoothness):
11161112
if len(albedo_tensor.shape) == 2:
1117-
albedo_pil_single = tensor_to_pil_single(albedo_tensor)
1113+
albedo_pil_single = tensor_to_pil(albedo_tensor)
11181114
albedo_pil = albedo_pil_single.convert("RGB")
11191115
else:
11201116
albedo_pil = tensor_to_pil(albedo_tensor)
11211117

11221118
if len(normal_tensor.shape) == 2:
1123-
normal_pil_single = tensor_to_pil_single(normal_tensor)
1119+
normal_pil_single = tensor_to_pil(normal_tensor)
11241120
normal_pil = normal_pil_single.convert("RGB")
11251121
else:
11261122
normal_pil = tensor_to_pil(normal_tensor)
11271123

11281124
if len(smoothness_tensor.shape) == 2:
1129-
smoothness_pil_single = tensor_to_pil_single(smoothness_tensor)
1125+
smoothness_pil_single = tensor_to_pil(smoothness_tensor)
11301126
smoothness_pil = smoothness_pil_single.convert("RGB")
11311127
else:
11321128
smoothness_pil = tensor_to_pil(smoothness_tensor)
@@ -1222,7 +1218,7 @@ def INPUT_TYPES(cls):
12221218
def node_function(self, images, folder_path, filename_prefix):
12231219
for index, image in enumerate(images):
12241220
if len(image.shape) == 2:
1225-
pil_single = tensor_to_pil_single(image)
1221+
pil_single = tensor_to_pil(image)
12261222
pil = pil_single.convert("RGB")
12271223
else:
12281224
pil = tensor_to_pil(image)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Python Script
6363
6464
Load LoRA Dual
6565
"""
66-
version = "1.0.82"
66+
version = "1.0.83"
6767
license = { file = "LICENSE" }
6868
dependencies = [
6969
"googletrans",

0 commit comments

Comments
 (0)