Javatpoint Logo
Javatpoint Logo

Image loading and transformation for Style Transferring in PyTorch

After importing all the necessary libraries and adding VGG-19 to our device, we have to load images in the memory on which we want to apply for style transfer. We have a content image, and style image and the target image will be the combination of both these images. Not every image needs to have the same size or pixel. To make the images equal, we will also apply the image transformation process.

Image loading and transformation for Style Transferring in PyTorch

Image Loading

We have to load the content image and style image in memory so that we can perform the operation on that. The loading process plays a vital role in the style transferring process. We need images in memory and style transferring process will not be possible before the loading process.

Code:

Image Conversion

Before importing our images, we need to convert our images from tensor as to numpy images to ensure the compatibility with the plot package. We have done this before with the familiar image_converts helper function which we have previously used in Image Transforms in Image Recognition.

If we run this helper method then it will generate the error. We have to remove the single dimensional entries from the shape of the image and from the shape of the array. So we will squeeze our image before the transpose method.

Plotting the images

Code:

When we run it on Google Colab Notebook, it will give us the expected output as:

Image loading and transformation for Style Transferring in PyTorch





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA