Blog

Convert Images to Tensors in Pytorch and Tensorflow | by Ng Wai Foong | Towards Data Science

As you have known, tensors represents the building blocks for your machine learning project. They are are immutable and can only be created and not updated. Handling tensors is complicated since it is largely dependent on the framework that you used and there is no standardization on how to code it.

As a result, you will often stuck in a situation in which you have to perform custom manipulations such as converting from Pytorch to Tensorflow or changing the dimension of the tensors. Toaster Ovens

Convert Images to Tensors in Pytorch and Tensorflow | by Ng Wai Foong | Towards Data Science

In this tutorial, you will learn to:

Let’s proceed to the next section and start installing all the necessary Python packages.

It is highly recommended to create a new virtual environment before you continue with the installation.

Run the following command to install both torch and torchvision packages.

torchvision is an essential package which provides quite a number of image transformation functions such as resizing and cropping.

In addition, you need to install Python Imaging Library (PIL) which complements torchvision when loading your images. You can install it as follows:

Tensorflow installation is a lot more straightforward now since version 2. Install it with the following command:

Once you are done with the installation, proceed to the next section for the implementation.

Convert Images to Tensors in Pytorch and Tensorflow | by Ng Wai Foong | Towards Data Science

Heating Cables Senior AI Engineer@Yoozoo | Content Writer #NLP #datascience #programming #machinelearning | Linkedin: https://www.linkedin.com/in/wai-foong-ng-694619185/