Quantcast
Viewing all articles
Browse latest Browse all 14185

read images using opencv inside tensorflow data loader

how to use opencv to read images and augument data for a tensoflow data loader, the filepath comming from tensorflow data loader is not string

self.original_image = cv2.imread(input_path)

TypeError: Can't convert object to 'str' for 'filename'

class augmentImage:  def __init__(self, height, width) -> None:    self.height = height    self.width = width    self.orignial_image = None    self.target = None    self.source = None  def __call__(self,image_file ):    self.augment(image_file)  def augment(self,input_path):      # Read the image      self.original_image = cv2.imread(input_path)      self.image =  self.original_image.copy()      return tf.cast(cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB), tf.float32)
agumentation = augmentImage(256, 256)def load_image_train(image_file):  input_image, real_image = agumentation(image_file)  input_image, real_image = normalize(input_image, real_image)  return input_image, real_imageimg_list = glob.glob('/content/data/dataset_pix2pix/train/*.jpg')train_dataset = tf.data.Dataset.from_tensor_slices(img_list)#(str(PATH / 'train/*.jpg'))train_dataset = train_dataset.map(load_image_train,                                  num_parallel_calls=tf.data.AUTOTUNE)

Viewing all articles
Browse latest Browse all 14185

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>