Search Here

Resize Image using Python for Deep Learning Model VGG19

 In this article, you will learn how to read images from the current working directory and resize that image into input shape (224,224,3) for the deep learning model VGG19.

Resize Image using Python for Deep Learning Model VGG19

How to get the current working directory

In python, we can use getcwd() to get into the current working directory. For example, if we are using PyCharm and have the following project structure.

Enjoy Free Tools: Explore Free Online Image Resizer Tool

Deep_Learning

images

img_1

img_2

img_3

model_trainig

train.py

Read More: Image Super Resolution Using SRGAN in Keras and TensorFlow

Now if we want to read images from images directory, than we will use os.getcwd()

import os
directory = os.getcwd()

This code will give us the path of Deep_Learning means it gives us the root directory path. Now to get inside the images directory we will use the below code.

import os
directory = os.getcwd()
img_dir = os.path.join(directory, "images")

Resize Image in Input Shape (224,224,3)

To feed input images to train our model some time we need to convert the original image into a pre-trained model (VGG19) input shape. To achieve this we need to resize the original image. The below code snippet shows how to convert or resize an image into desired shape image.

bulk_resize_image.py

The above code will read images from the images directory and resize that image and save that image into the same directory (replace original images). If you don't want to replace original images then just save resized images into another directory.

Post a Comment

0 Comments