Add a test node for simple sampler tonemapping.

This commit is contained in:
comfyanonymous
2023-04-17 12:20:29 -04:00
committed by GitHub
parent 9e5c4c0666
commit 466aaa1302
+41
View File
@@ -0,0 +1,41 @@
import torch
class ModelSamplerTonemapNoiseTest:
@classmethod
def INPUT_TYPES(s):
return {"required": { "model": ("MODEL",),
"multiplier": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 100.0, "step": 0.01}),
}}
RETURN_TYPES = ("MODEL",)
FUNCTION = "patch"
CATEGORY = "custom_node_experiments"
def patch(self, model, multiplier):
def sampler_tonemap_reinhard(cond, uncond, cond_scale):
noise_pred = (cond - uncond)
noise_pred_vector_magnitude = (torch.linalg.vector_norm(noise_pred, dim=(1)) + 0.0000000001)[:,None]
noise_pred /= noise_pred_vector_magnitude
mean = torch.mean(noise_pred_vector_magnitude, dim=(1,2,3), keepdim=True)
std = torch.std(noise_pred_vector_magnitude, dim=(1,2,3), keepdim=True)
top = (std * 3 + mean) * multiplier
#reinhard
noise_pred_vector_magnitude *= (1.0 / top)
new_magnitude = noise_pred_vector_magnitude / (noise_pred_vector_magnitude + 1.0)
new_magnitude *= top
return uncond + noise_pred * new_magnitude * cond_scale
m = model.clone()
m.set_model_sampler_cfg_function(sampler_tonemap_reinhard)
return (m, )
NODE_CLASS_MAPPINGS = {
"ModelSamplerTonemapNoiseTest": ModelSamplerTonemapNoiseTest,
}