code: def _transform_row(mnist_row):
      # For this example, the images are stored as simpler ndarray (28,28), but the
      # training network expects 3-dim images, hence the additional lambda transform.
      transform = transforms.Compose(
          [
              transforms.Lambda(lambda nd: nd.reshape(28, 28, 1)),
              transforms.ToTensor(),
              transforms.Normalize((0.1307,), (0.3081,)),
          ]
      )
      # In addition, the petastorm pytorch DataLoader does not distinguish the notion of
      # data or target transform, but that actually gives the user more flexibility
      # to make the desired partial transform, as shown here.
      result_row = {
          "image": transform(mnist_row["image"]),
          "digit": mnist_row["digit"],
      }
  
      return result_row
  
file_path: petastorm/examples/mnist/pytorch_example.py
imports: from __future__ import division, print_function
  import argparse
  import pyarrow
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from torchvision import transforms
  from examples.mnist import DEFAULT_MNIST_DATA_PATH
  from petastorm import make_reader, TransformSpec
  from petastorm.pytorch import DataLoader
label_desc: Use image node_id 3 for calling a global function with example usage: _transform_row(mnist_row) and returns: result_row