class_docstr: Dataset for textual inversion, pairing prompts with normalized image tensors.
class_docstr_tok: ["Dataset","for","textual","inversion",",","pairing","prompts","with","normalized","image","tensors","."]
docstr: Converts a PIL image into an appropriately transformed tensor.
docstr_tok: ["Converts","a","PIL","image","into","an","appropriately","transformed","tensor","."]
code: def _convert_img_to_tensor(self, img: Image.Image) -> torch.Tensor:
      """Converts a PIL image into an appropriately transformed tensor."""
      if self.center_crop:
          img = transforms.CenterCrop(size=min(img.size))(img)
      img_tensor = self._base_img_trans(img)
      # Normalize the tensor to be in the range [-1, 1]
      img_tensor = (img_tensor - 0.5) * 2.0
      return img_tensor
  
file_path: determined/examples/diffusion/textual_inversion_stable_diffusion/detsd/data.py
imports: import logging
  import os
  from pathlib import Path
  from typing import List, Sequence, Tuple
  import PIL
  import torch
  from detsd import defaults
  from PIL import Image
  from torch.utils.data import Dataset
  from torchvision import transforms
label_desc: Use image node_id 3 for calling the TextualInversionDataset obj's underlying member method code with example usage: obj._convert_img_to_tensor(img) and returns: img_tensor