Files
ComfyUI/custom_nodes/comfyui_ultimatesdupscale/test/tensor_utils.py
jaidaken f09734b0ee
Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Has been cancelled
Execution Tests / test (macos-latest) (push) Has been cancelled
Execution Tests / test (ubuntu-latest) (push) Has been cancelled
Execution Tests / test (windows-latest) (push) Has been cancelled
Test server launches without errors / test (push) Has been cancelled
Unit Tests / test (macos-latest) (push) Has been cancelled
Unit Tests / test (ubuntu-latest) (push) Has been cancelled
Unit Tests / test (windows-2022) (push) Has been cancelled
Add custom nodes, Civitai loras (LFS), and vast.ai setup script
Includes 30 custom nodes committed directly, 7 Civitai-exclusive
loras stored via Git LFS, and a setup script that installs all
dependencies and downloads HuggingFace-hosted models on vast.ai.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 00:56:42 +00:00

28 lines
1007 B
Python

import torchvision.transforms.functional as TF
def img_tensor_mae(tensor1, tensor2):
"""Calculate the mean absolute difference between two image tensors."""
# Remove batch dimensions if present
tensor1 = tensor1.squeeze(0).cpu()
tensor2 = tensor2.squeeze(0).cpu()
if tensor1.shape != tensor2.shape:
raise ValueError(
f"Tensors must have the same shape for comparison. Got {tensor1.shape=} and {tensor2.shape=}."
)
return (tensor1 - tensor2).abs().mean().item()
def blur(tensor, kernel_size=9, sigma=None):
"""Apply Gaussian blur to an image tensor."""
# [1, H, W, C] -> [1, C, H, W]
if tensor.ndim == 4:
tensor = tensor.permute(0, 3, 1, 2)
elif tensor.ndim == 3:
tensor = tensor.permute(2, 0, 1).unsqueeze(0)
else:
raise ValueError(f"Expected a 3D or 4D tensor, got {tensor.ndim=}")
return TF.gaussian_blur(tensor, kernel_size=kernel_size, sigma=sigma).permute( # type: ignore
0, 2, 3, 1
)