mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-09 19:27:40 +08:00
Merge branch 'comfyanonymous:master' into master
This commit is contained in:
commit
1d9338b4b9
@ -18,6 +18,7 @@ class Output:
|
|||||||
setattr(self, key, item)
|
setattr(self, key, item)
|
||||||
|
|
||||||
def clip_preprocess(image, size=224, mean=[0.48145466, 0.4578275, 0.40821073], std=[0.26862954, 0.26130258, 0.27577711], crop=True):
|
def clip_preprocess(image, size=224, mean=[0.48145466, 0.4578275, 0.40821073], std=[0.26862954, 0.26130258, 0.27577711], crop=True):
|
||||||
|
image = image[:, :, :, :3] if image.shape[3] > 3 else image
|
||||||
mean = torch.tensor(mean, device=image.device, dtype=image.dtype)
|
mean = torch.tensor(mean, device=image.device, dtype=image.dtype)
|
||||||
std = torch.tensor(std, device=image.device, dtype=image.dtype)
|
std = torch.tensor(std, device=image.device, dtype=image.dtype)
|
||||||
image = image.movedim(-1, 1)
|
image = image.movedim(-1, 1)
|
||||||
|
|||||||
@ -37,9 +37,14 @@ def validate_and_cast_response (response):
|
|||||||
if not data or len(data) == 0:
|
if not data or len(data) == 0:
|
||||||
raise Exception("No images returned from API endpoint")
|
raise Exception("No images returned from API endpoint")
|
||||||
|
|
||||||
# Get base64 image data
|
# Initialize list to store image tensors
|
||||||
image_url = data[0].url
|
image_tensors = []
|
||||||
b64_data = data[0].b64_json
|
|
||||||
|
# Process each image in the data array
|
||||||
|
for image_data in data:
|
||||||
|
image_url = image_data.url
|
||||||
|
b64_data = image_data.b64_json
|
||||||
|
|
||||||
if not image_url and not b64_data:
|
if not image_url and not b64_data:
|
||||||
raise Exception("No image was generated in the response")
|
raise Exception("No image was generated in the response")
|
||||||
|
|
||||||
@ -57,9 +62,12 @@ def validate_and_cast_response (response):
|
|||||||
|
|
||||||
# Convert to numpy array, normalize to float32 between 0 and 1
|
# Convert to numpy array, normalize to float32 between 0 and 1
|
||||||
img_array = np.array(img).astype(np.float32) / 255.0
|
img_array = np.array(img).astype(np.float32) / 255.0
|
||||||
|
img_tensor = torch.from_numpy(img_array)
|
||||||
|
|
||||||
# Convert to torch tensor and add batch dimension
|
# Add to list of tensors
|
||||||
return torch.from_numpy(img_array)[None,]
|
image_tensors.append(img_tensor)
|
||||||
|
|
||||||
|
return torch.stack(image_tensors, dim=0)
|
||||||
|
|
||||||
class OpenAIDalle2(ComfyNodeABC):
|
class OpenAIDalle2(ComfyNodeABC):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user