Ctrl+K
Logo image Logo image

Site Navigation

  • API Reference
  • Examples

Site Navigation

  • API Reference
  • Examples

Section Navigation

  • PyFlink Table
  • PyFlink DataFrame
  • PyFlink Multimodal
    • Image
    • Video
    • Utilities
  • PyFlink DataStream
  • PyFlink Common

pyflink.multimodal.operators.image_nsfw_score#

image_nsfw_score(*columns, hf_nsfw_model='Falconsai/nsfw_image_detection', model_sharing=None, concurrency=None, batch_size=None, num_gpus=None, gpu_type=None)[source]#

Create an NSFW scoring UDF (HuggingFace image classification-based).

Requires pip install transformers torch. This is a pandas batch UDF that supports GPU acceleration via num_gpus / gpu_type. Set num_gpus to request GPU resources from the DataFrame UDF runtime.

Parameters
  • *columns – Optional image column(s). When provided, the UDF is applied directly instead of returning a factory.

  • hf_nsfw_model – HuggingFace model ID for NSFW classification. Defaults to the built-in NSFW classifier model.

  • model_sharing – Model sharing mode across parallel subtasks. None uses per-process caching.

  • concurrency – UDF concurrency. None uses the framework default.

  • batch_size – Pandas batch size. None uses the framework default.

  • num_gpus – Fractional GPU count per subtask, e.g. 0.5. None runs on CPU.

  • gpu_type – Required GPU type, e.g. "A10". None accepts any available GPU.

Returns

A UDF that returns a float NSFW probability score in [0, 1] or None for null inputs. Higher values indicate stronger NSFW confidence. Use downstream filtering (e.g. > 0.5) to convert to a boolean decision.

Example::
>>> # As a reusable variable
>>> nsfw = image_nsfw_score()
>>> df = df.with_column("nsfw", nsfw(col("img")))
>>> nsfw_gpu = image_nsfw_score(num_gpus=1.0)
>>> df = df.with_column("nsfw", nsfw_gpu(col("img")))
>>>
>>> # Inline
>>> df = df.with_column("nsfw", image_nsfw_score(col("img")))
>>> df = df.filter(image_nsfw_score(col("img")) > 0.5)

previous

pyflink.multimodal.operators.image_face_blur

next

pyflink.multimodal.operators.image_aesthetic_score

Show Source

Created using Sphinx 4.5.0.