(dataset,
                                            training,
                                            predict_image_train_weight=0.01)
return dataset
Preprocessing for cifar10 that flattens it and appends targets.
Preprocessing for cifar10 that flattens it and appends targets.
Preprocessing for cifar10 that flattens it and appends targets .
def cifar10_augmentation_flatten_preprocess(dataset,
                                            training,
                                            predict_image_train_weight=0.01):
  """Preprocessing for cifar10 that flattens it and appends targets."""

  def augment(features, targets):
    features['image'] = _cifar_augment_image(features['image'])
    return features, targets

  def flatten_image(features, targets):
    """Flatten the image."""
    img = features['image']
    flat = tf.cast(tf.reshape(img, [-1]), tf.int64)
    tgt = tf.expand_dims(targets, axis=0)
    flat_with_target = tf.concat([flat, tgt], axis=0)
    new_features = {}
    new_features['image'] = flat_with_target
    predict_image_weight = predict_image_train_weight if training else 0.0
    mask_begin = tf.ones_like(flat)
    mask_begin = tf.cast(mask_begin, tf.float32) * predict_image_weight
    mask_end = tf.cast(tf.ones_like(tgt), tf.float32)
    new_features['mask'] = tf.concat([mask_begin, mask_end], axis=0)
    return new_features, flat_with_target

  if training:
    dataset = dataset.map(augment)
  dataset = dataset.map(flatten_image)

  return dataset
def cifar10_augmentation_flatten_preprocess ( dataset , training , predict_image_train_weight = 0.01 ) : def augment ( features , targets ) : features [ 'image' ] = _cifar_augment_image ( features [ 'image' ] ) return features , targets def flatten_image ( features , targets ) : """Flatten the image.""" img = features [ 'image' ] flat = tf . cast ( tf . reshape ( img , [ - 1 ] ) , tf . int64 ) tgt = tf . expand_dims ( targets , axis = 0 ) flat_with_target = tf . concat ( [ flat , tgt ] , axis = 0 ) new_features = { } new_features [ 'image' ] = flat_with_target predict_image_weight = predict_image_train_weight if training else 0.0 mask_begin = tf . ones_like ( flat ) mask_begin = tf . cast ( mask_begin , tf . float32 ) * predict_image_weight mask_end = tf . cast ( tf . ones_like ( tgt ) , tf . float32 ) new_features [ 'mask' ] = tf . concat ( [ mask_begin , mask_end ] , axis = 0 ) return new_features , flat_with_target if training : dataset = dataset . map ( augment ) dataset = dataset . map ( flatten_image ) return dataset