Commit 54a80323 authored by Amir MOHAMMADI's avatar Amir MOHAMMADI

add a function to load png images

parent 70e0b851
...@@ -197,3 +197,25 @@ def image_augmentation_parser(filename, ...@@ -197,3 +197,25 @@ def image_augmentation_parser(filename,
features['key'] = filename features['key'] = filename
return features, label 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment