Thursday, 3 October 2019

Load Image Files and Make Ready-to-Train Data

TensorFlow has built-in utility functions to read file, decode image format, convert value types, and resize image data before training, the `load_img` utility function below show how to load a JPEG, JPG file to ready-to-train data of shape (width,height,channels):

Example to get file paths:
Dataset = tf.data.Dataset.list_files(DATA_DIR+"/roses/*").take(10);

Source code:
def load_img(Path):
  File = tf.io.read_file(Path);
  Img  = tf.image.decode_jpeg(File, channels=3);
  Img  = tf.image.convert_image_dtype(Img,tf.float32);
  Img  = tf.image.resize(Img, [IMG_WIDTH,IMG_HEIGHT]);
  return Img;

No comments:

Post a Comment