Home > front end >  I want to do Data Augmentation so i wanted to convert image to tensors which I'm not able to do
I want to do Data Augmentation so i wanted to convert image to tensors which I'm not able to do

Time:08-27

Here is the code:

from os import listdir
from os.path import isfile, join

vvy_imgs = []
#images to tensors
for img in np.array([f for f in listdir('E:/vachan') if isfile(join('E:/vachan', f))]): # filepaths 
    print(img) # shows it's of jpg extension
    tensor = tf.io.decode_jpeg(img, channels=3)
    vvy_imgs = np.append(vvy_imgs, tensor)

#Data Augmentation
for img in vvy_imgs:
    tf.image.flip_left_right(img)
    vvy_imgs = np.append(vvy_imgs, img)

but it is showing error

InvalidArgumentError: Unknown image file format. One of JPEG, PNG, GIF, BMP required. [Op:DecodeJpeg]

though all the images are of '.jpg' extension.

CodePudding user response:

Seems like img is a path to an image and not an image. Maybe try:

image = tf.io.read_file(img)
tensor= tf.io.decode_jpeg(image)
...
  • Related