0

I want to get the input images of the trainset unlabeled.

When loading the dataset I get an odd dictionary first, but I got rid of it.

What I just can't manage is to resize all images to (200,200,3).

My attempt so far:

@tf.function
def pre(img):
    return img["image"]

training_daten = tfds.as_numpy(tfds.load(name="cars196", batch_size = 8, split="train").map(pre))

# I got the pictures now, but they're all of a different shape

def pre2(i):
    img_pil = Image.fromarray(i)
    i = img_pil.thumbnail((200,200), Image.ANTIALIAS)
    return np.array(i)

training_daten = [list(map(pre2,i)) for i in training_daten]

I'm already 5 hours on this.. Thank you very much!

EDIT: Output of the first batch of my code is: [array(None, dtype=object), array(None, dtype=object), array(None, dtype=object), array(None, dtype=object), array(None, dtype=object), array(None, dtype=object), array(None, dtype=object), array(None, dtype=object)]

So, something doesn't work.

1 Answers1

0

Instead of using .thumbnail method, you can use .resize method, because the thumbnail method doesn't shape them all in one shape, but calculates the best size and the size you give serves as upper bound on the size.

i = img_pil.resize((200,200), Image.ANTIALIAS)

See this answer for difference between them.

Vicrobot
  • 3,795
  • 1
  • 17
  • 31