diff --git a/bob/learn/tensorflow/dataset/image.py b/bob/learn/tensorflow/dataset/image.py index c5888b8da966165e486e62251c975e3452160f81..b731e55260cac42d6e56edec37f4f6cfb65627f7 100644 --- a/bob/learn/tensorflow/dataset/image.py +++ b/bob/learn/tensorflow/dataset/image.py @@ -197,3 +197,25 @@ def image_augmentation_parser(filename, features['key'] = filename return features, label + + +def load_pngs(img_path, img_shape): + """Read png files using tensorflow API + You must know the shape of the image beforehand to use this function. + + Parameters + ---------- + img_path : str + Path to the image + img_shape : list + A list or tuple that contains image's shape in channels_last format + + Returns + ------- + object + The loaded png file + """ + img_raw = tf.read_file(img_path) + img_tensor = tf.image.decode_png(img_raw, channels=img_shape[-1]) + img_final = tf.reshape(img_tensor, img_shape) + return img_final