peal.visualization.visualize_counterfactual_gradients.create_label_image

peal.visualization.visualize_counterfactual_gradients.create_label_image(text, image_size, font_size=50)[source]

Render a text caption as an image tensor of a given size.

The text is drawn centred in black on a white canvas (RGB when C == 3, greyscale otherwise) with arial.ttf if available, else PIL’s default font.

Parameters:
  • text (str) – Caption to draw.

  • image_size (tuple of int) – (C, H, W) of the target image.

  • font_size (int, optional) – Font size in pixels. Default 50.

Returns:

Tensor of shape (1, C, H, W) with values in [0, 1].

Return type:

torch.Tensor