Nodes/comfyui-piq/StyleScore
ComfyUI Node

StyleScore

The Gram-matrix metric that measures the 'feel' of an image

By Laurent2916·Created about a year ago·Updated about a year ago· 0
StyleScore
  • image_a
  • image_b
  • style_loss
feature_extractor
replace_poolingfalse
distance
reduction
normalize_featuresfalse

ContentScore measures what's in the picture. StyleScore measures how it's painted. It's the classic style-transfer StyleLoss - VGG features compared via their Gram matrices, which capture the correlations between feature activations at each layer. Roughly: the Gram matrix of a painting tells you about its brushwork, color harmony, and texture without caring where any of it sits. As a standalone metric, StyleScore answers "does this image have the same stylistic feel as the reference, even if the subject changed?" Lower is better - 0.0 means the styles match exactly.

It's one of the seventeen nodes in comfyui-piq, Laurent Fainsin's wrapper around the piq library.

How it works. Both images pass through a VGG network (vgg16 or vgg19), and at several layers (piq uses relu1_2, relu2_2, relu3_3, relu4_3 by default) the features are turned into Gram matrices - outer products of the feature channels that encode "which texture/color patterns tend to co-occur here." Those Gram matrices from both images are compared with a distance (mse/mae), weighted, and pooled (reduction) into the score. Because Gram matrices drop spatial location, two images can share a style score while depicting totally different scenes - that's the feature, not a bug. normalize_features and replace_pooling are the same tuning knobs as ContentScore.

Shared gotcha: VGG weights download on first run. vgg16/vgg19 are ImageNet-pretrained, torchvision fetches them from pytorch.org (~528–549 MB) on first use and caches in ~/.cache/torch. First run needs internet; every run after is local.

Inputs a beginner actually sets:

  • image_a / image_b - candidate vs. reference; image_b is ground truth.
  • feature_extractor - vgg16 (default) unless you need the extra depth of vgg19.
  • distance / reduction - mse and mean for one comparable number.

The style_loss output is a FLOAT, lower better.

Installing. ComfyUI Manager, search "comfyui-piq", Install. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/Laurent2916/comfyui-piq.git
pip install -r custom_nodes/comfyui-piq/requirements.txt

Requirements is one line (piq>=0.8.0); Python 3.12+; repo archived but functional.

The honest take. StyleScore is the node you reach for when your question is genuinely about style - "did this LoRA reproduce the target artist's texture and palette," "is this img2img pass preserving the original's look." It's a real metric with a real job, but it's also the most easily misunderstood one here: a low style score tells you nothing about whether the subject matches. Run it with ContentScore if you want both axes, and remember both are deep-feature distances - same weight-download caveat, same "GPU helps" advice as LPIPS.

Categorypiq

Inputs (7)

NameTypeDefaultDescription
image_aIMAGEInput image
image_bIMAGEReference image
feature_extractorCOMBONeural network for feature extraction
replace_poolingBOOLEANfalseReplace max pooling with average pooling
distanceCOMBODistance metric
reductionCOMBOReduction method
normalize_featuresBOOLEANfalseWhether to normalize extracted features

Outputs (1)

NameTypeDescription
style_lossFLOATStyle Loss Based on Deep Features