pyflink.multimodal.operators.image_aesthetic_score#
- image_aesthetic_score(*columns, hf_scorer_model='shunk031/aesthetics-predictor-v2-sac-logos-ava1-l14-linearMSE', model_sharing=None, concurrency=None, batch_size=None, num_gpus=None, gpu_type=None)[source]#
Create an aesthetic quality scoring UDF (HuggingFace aesthetics predictor-based).
Requires
pip install transformers torch. This is a pandas batch UDF that supports GPU acceleration vianum_gpus/gpu_type. Setnum_gpusto request GPU resources from the DataFrame UDF runtime.The default scorer is a regression head, not a probability model. Its score is divided by 10 and clamped to
[0, 1]because the default LAION aesthetic predictor is trained on AVA/SAC-style 1-10 targets. Custom scorer outputs are expected to already use a[0, 1]scale and are clamped defensively. Custom model IDs must provide local safetensors head weights matching the built-in head architectureprojection_dim -> 1024 -> 128 -> 64 -> 16 -> 1; only the built-in default model may fall back totrust_remote_code=Truewhen those weights are unavailable.- Parameters
*columns – Optional image column(s). When provided, the UDF is applied directly instead of returning a factory.
hf_scorer_model – HuggingFace model ID for aesthetic scoring. Default
"shunk031/aesthetics-predictor-v2-sac-logos-ava1-l14-linearMSE".model_sharing – Model sharing mode across parallel subtasks.
Noneuses per-process caching.concurrency – UDF concurrency.
Noneuses the framework default.batch_size – Pandas batch size.
Noneuses the framework default.num_gpus – Fractional GPU count per subtask, e.g.
0.5.Noneruns on CPU.gpu_type – Required GPU type, e.g.
"A10".Noneaccepts any available GPU.
- Returns
A UDF that returns a normalized float aesthetic quality score in
[0, 1]orNonefor null inputs.
- Example::
>>> # As a reusable variable >>> aesthetic = image_aesthetic_score() >>> df = df.with_column("aesthetic", aesthetic(col("img"))) >>> aesthetic_gpu = image_aesthetic_score(num_gpus=1.0) >>> df = df.with_column("aesthetic", aesthetic_gpu(col("img"))) >>> >>> # Inline >>> df = df.with_column("aesthetic", image_aesthetic_score(col("img")))