def dims_to_targetshape(data_dims, batch_size=None, placeholder=False):
  """Prepends either batch size/None (for placeholders) to a data shape tensor.

  Args:
    data_dims: list, indicates shape of the data, ignoring the batch size.
      For an RGB image this could be [224, 224, 3] for example.
    batch_size: scalar, indicates the batch size for SGD.
    placeholder: bool, indicates whether the returned dimensions are going to
      be used to construct a TF placeholder.
  Returns:
    shape: A tensor with a batch dimension prepended to the data shape.
  """
  if batch_size is not None and batch_size != 0:
    shape = [batch_size]
  elif placeholder is True:
    shape = [None]
  else:
    shape = [-1]
  shape.extend(data_dims)

  return shape