class_docstr: Encode an image with a supported file encoding.
class_docstr_tok: ["Encode","an","image","with","a","supported","file","encoding","."]
docstr: Serialize an image as file bytes.
  
  Args:
      data: A dictionary containing a key called "samples", which contains
          an image tensor of shape [C, H, W].
  
  Returns:
      The transformed data.
docstr_tok: ["Serialize","an","image","as","file","bytes",".","Args",":","data",":","A","dictionary","containing","a","key","called","``","samples","''",",","which","contains","an","image","tensor","of","shape","[","C",",","H",",","W","]",".","Returns",":","The","transformed","data","."]
code: def __call__(
      self, data: Dict[str, Union[torch.Tensor, int]]
  ) -> Dict[str, Union[torch.Tensor, int]]:
      """
      Serialize an image as file bytes.
  
      Args:
          data: A dictionary containing a key called "samples", which contains
              an image tensor of shape [C, H, W].
  
      Returns:
          The transformed data.
      """
      x = data["samples"]
  
      if self.file_encoding == "fCHW":
          x = (x * 255).byte().to(dtype=torch.int32).reshape(-1)
      elif self.file_encoding == "fHWC":
          x = (
              (x * 255)
              .byte()
              .to(dtype=torch.int32)
              .permute(1, 2, 0)
              .reshape(-1)
          )
      elif self.file_encoding == "TIFF":
          x = _bytes_to_int32(_image_to_bytes(x, format="tiff"))
      elif self.file_encoding == "PNG":
          x = _bytes_to_int32(
              _image_to_bytes(x, format="png", compress_level=0)
          )
      elif self.file_encoding == "JPEG":
          quality = getattr(
              self.opts, "image_augmentation.pil_save.quality"
          )
          x = _bytes_to_int32(
              _image_to_bytes(x, format="jpeg", quality=quality)
          )
      else:
          raise NotImplementedError(
              f"Invalid file encoding {self.file_encoding}. Expected one of 'fCHW, fHWC, TIFF, PNG, JPEG'."
          )
      data["samples"] = x
      return data
  
imports: import argparse
  import io
  from typing import Dict, Union
  import numpy
  import torch
  from PIL import Image
  from data.transforms import TRANSFORMATIONS_REGISTRY, BaseTransformation
label_desc: Use image node_id 2 for calling the PILSave obj's underlying member method code with example usage: obj.__call__(data) and returns: data