INNER CODE UNIT · Python
get_entropy
Extraltodeus/ComfyUI-AutomaticCFG · nodes.py:96
def get_entropy(tensor):
hist = np.histogram(tensor.cpu(), bins=100)[0]
hist = hist / hist.sum()
hist = hist[hist > 0]
return -np.sum(hist * np.log2(hist))
def map_sigma(sigma, sigmax, sigmin):
return 1 + ((sigma - sigmax) * (0 - 1)) / (sigmin - sigmax)
def center_latent_mean_values(latent, per_channel, mult):
for b in range(len(latent)):
if per_channel:
for c in range(len(latent[b])):
latent[b][c] -= latent[b][c].mean() * mult
else:
latent[b] -= latent[b].mean() * mult
return latent