courses/machine_learning/deepdive/08_image/flowersmodeltpu/trainer/preprocess.py
def _convert_to_example(filename, image_buffer, label_int, label_str, height,
                        width):
  """Build an Example proto for an example.

  Args:
    filename: string, path to an image file, e.g., '/path/to/example.JPG'
    image_buffer: string, JPEG encoding of RGB image
    label_int: integer, identifier for ground truth (0-based)
    label_str: string, identifier for ground truth, e.g., 'daisy'
    height: integer, image height in pixels
    width: integer, image width in pixels
  Returns:
    Example proto
  """
  colorspace = 'RGB'
  channels = 3
  image_format = 'JPEG'

  example = tf.train.Example(
      features=tf.train.Features(
          feature={
              'image/height': _int64_feature(height),
              'image/width': _int64_feature(width),
              'image/colorspace': _bytes_feature(colorspace),
              'image/channels': _int64_feature(channels),
              'image/class/label': _int64_feature(label_int +
                                                  1),  # model expects 1-based
              'image/class/synset': _bytes_feature(label_str),
              'image/format': _bytes_feature(image_format),
              'image/filename': _bytes_feature(os.path.basename(filename)),
              'image/encoded': _bytes_feature(image_buffer)
          }))
  return example
Build an Example proto for an example.

  Args:
    filename: string, path to an image file, e.g., '/path/to/example.JPG'
    image_buffer: string, JPEG encoding of RGB image
    label_int: integer, identifier for ground truth (0-based)
    label_str: string, identifier for ground truth, e.g., 'daisy'
    height: integer, image height in pixels
    width: integer, image width in pixels
  Returns:
    Example proto
  
Build an Example proto for an example.
Build an Example proto for an example .
def _convert_to_example(filename, image_buffer, label_int, label_str, height,
                        width):
  colorspace = 'RGB'
  channels = 3
  image_format = 'JPEG'
  example = tf.train.Example(
      features=tf.train.Features(
          feature={
              'image/height': _int64_feature(height),
              'image/width': _int64_feature(width),
              'image/colorspace': _bytes_feature(colorspace),
              'image/channels': _int64_feature(channels),
              'image/class/label': _int64_feature(label_int +
                                                  1),  
              'image/class/synset': _bytes_feature(label_str),
              'image/format': _bytes_feature(image_format),
              'image/filename': _bytes_feature(os.path.basename(filename)),
              'image/encoded': _bytes_feature(image_buffer)
          }))
  return example
def _convert_to_example ( filename , image_buffer , label_int , label_str , height , width ) : colorspace = 'RGB' channels = 3 image_format = 'JPEG' example = tf . train . Example ( features = tf . train . Features ( feature = { 'image/height' : _int64_feature ( height ) , 'image/width' : _int64_feature ( width ) , 'image/colorspace' : _bytes_feature ( colorspace ) , 'image/channels' : _int64_feature ( channels ) , 'image/class/label' : _int64_feature ( label_int + 1 ) , 'image/class/synset' : _bytes_feature ( label_str ) , 'image/format' : _bytes_feature ( image_format ) , 'image/filename' : _bytes_feature ( os . path . basename ( filename ) ) , 'image/encoded' : _bytes_feature ( image_buffer ) } ) ) return example
Build an Example proto for an example.
Build an Example proto for an example .
"""Build an Example proto for an example.

  Args:
    filename: string, path to an image file, e.g., '/path/to/example.JPG'
    image_buffer: string, JPEG encoding of RGB image
    label_int: integer, identifier for ground truth (0-based)
    label_str: string, identifier for ground truth, e.g., 'daisy'
    height: integer, image height in pixels
    width: integer, image width in pixels
  Returns:
    Example proto
  """ # model expects 1-based
None
filename
string, path to an image file, e.g., '/path/to/example.JPG'
string path to an image file e . g . ' / path / to / example . JPG '
image_buffer
string, JPEG encoding of RGB image
string JPEG encoding of RGB image
label_int
integer, identifier for ground truth (0-based)
integer identifier for ground truth ( 0 - based )
label_str
string, identifier for ground truth, e.g., 'daisy'
string identifier for ground truth e . g . ' daisy '
height
integer, image height in pixels
integer image height in pixels
width
integer, image width in pixels
integer image width in pixels