{"id":27019,"date":"2023-02-14T07:00:00","date_gmt":"2023-02-14T14:00:00","guid":{"rendered":"https:\/\/cloudinary.com\/blog\/?p=27019"},"modified":"2025-02-16T02:22:30","modified_gmt":"2025-02-16T10:22:30","slug":"preprocess-images-for-deep-learning-in-python","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python","title":{"rendered":"How to Better Preprocess Images for Deep Learning in Python"},"content":{"rendered":"\n<p>As a data scientist, you likely use images for model training and inference. But before they\u2019re ready for you to use, images must undergo a set of transformations. This is called <em>image preprocessing<\/em>.&nbsp;<\/p>\n\n\n\n<p>Why would you need to preprocess your images? Image preprocessing can have major positive impacts on the neural networks you\u2019re training, including:&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ensuring their proper functioning. <\/strong>Many neural networks only function when images share the same dimensions. If this is the case for your neural network, all your images need to be resized and standardized.&nbsp;<\/li>\n\n\n\n<li><strong>Reducing costs. <\/strong>Retaining only the information needed for the task can reduce costs. For example, if color isn\u2019t essential for your machine learning, converting all your images to grayscale can reduce retention and processing costs.\u00a0This is a key benefit of using advanced tools like Cloudinary, which can efficiently preprocess images to grayscale or apply other cost-saving transformations.<\/li>\n\n\n\n<li><strong>Improving efficiency. <\/strong>For example, you can improve model training time by reducing your image sizes.<\/li>\n\n\n\n<li><strong>Increasing accuracy. <\/strong>Augmenting your images can artificially increase your training data, thereby enhancing the accuracy of the neural network you\u2019re training. This means changing the original images by applying transformations and then adding those image variations to your original set. Some common transformations that you apply can include saturation, rotation, colorization, and brightness. Cloudinary, as an advanced image management solution, offers these preprocessing features, enabling you to easily augment your images for better model performance.<\/li>\n<\/ul>\n\n\n\n<p>Now that you know why you need to preprocess your images, let\u2019s talk about how to do it.<\/p>\n\n\n\n<p>You\u2019ve probably used any one of Python\u2019s many packages, such as Pillow, Skimage, or OpenCV, to preprocess your images.&nbsp;<\/p>\n\n\n\n<p>But there\u2019s a better way. That\u2019s Cloudinary.<\/p>\n\n\n\n<p>Cloudinary is an image management solution that supports image uploads, cloud storage, and image transformations \u2014 the very features you need as a data scientist to preprocess images for deep learning in Python.&nbsp;<\/p>\n\n\n\n<p>Cloudinary enables you to normalize and augment your images more quickly and easily, without compromising quality. With Cloudinary, you can:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Upload images in bulk<\/li>\n\n\n\n<li>Store an unlimited number of images privately and securely<\/li>\n\n\n\n<li>Easily apply preprocessing methods, such as resizing, cropping, rotating, grayscaling, saturating, and much more, uniformly to all or some of the images you upload.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>Let\u2019s see how it\u2019s done.&nbsp;&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Demo: Streamline Your Image Preprocessing Workflow with Cloudinary<\/h2>\n\n\n\n<p>Let\u2019s explore how to streamline your image preprocessing workflow using Cloudinary. In this demo, we\u2019ll use Python code to prepare a set of images for a deep learning model that teaches the computer to recognize the difference between images of dogs and cats. While this demo only handles a few sample images, you can scale the actions executed in each step to meet your own project needs.<\/p>\n\n\n\n<p>Let\u2019s get started.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Get Cloudinary&nbsp;<\/h3>\n\n\n\n<p>If you don&#8217;t yet have a Cloudinary account, sign up for a <a href=\"https:\/\/cloudinary.com\/users\/register_free\" target=\"_blank\" rel=\"noreferrer noopener\">free one<\/a>. <\/p>\n\n\n\n<p>You can try out any effects described in this demo by copying the code to a clean file in your Python environment and running it. You can also follow this demo using a <a href=\"https:\/\/colab.research.google.com\/github\/cloudinary-devs\/image-preprocessing\/blob\/main\/samples.ipynb\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Jupyter Notebook<\/a> that will run the code against your Cloudinary account for you. Simply open the <a href=\"https:\/\/colab.research.google.com\/github\/cloudinary-devs\/image-preprocessing\/blob\/main\/samples.ipynb\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Jupyter Notebook<\/a> and then run each code snippet to see the Python code in action.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Configure Cloudinary<\/h3>\n\n\n\n<p>To create a clean project in the development environment of your choice, you need to set up your configuration. Create a new Python file called <code>animals.py<\/code>. Copy and paste the following code, replacing <code>&lt;cloudinary:\/\/1212121212121212:4567889asdf12345890cc@cloud_name&gt;<\/code> with your API environment variable value, which is the portion of your API environment variable after <code>CLOUDINARY_URL=<\/code>. (Find your <a href=\"https:\/\/cloudinary.com\/documentation\/how_to_integrate_cloudinary#account_details\" target=\"_blank\" rel=\"noreferrer noopener\">credentials<\/a> in the Dashboard page of your <a href=\"https:\/\/console.cloudinary.com\/console\" target=\"_blank\" rel=\"noreferrer noopener\">Cloudinary Console<\/a>.)<\/p>\n\n\n<div class='c-callout  c-callout--inline-title c-callout--warning'><strong class='c-callout__title'>Caution:<\/strong> <p>When you\u2019re writing your own applications, you should follow your organization\u2019s policies on storing proprietary data to prevent exposing your API secret.<\/p>\n<\/div>\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">import os\nos.environ&#91;<span class=\"hljs-string\">\"CLOUDINARY_URL\"<\/span>] = <span class=\"hljs-string\">\"&lt;cloudinary:\/\/1212121212121212:4567889asdf12345890cc@cloud_name&gt;\"<\/span>\n<span class=\"hljs-keyword\">print<\/span>(os.getenv(<span class=\"hljs-string\">\"CLOUDINARY_URL\"<\/span>))\n<span class=\"hljs-comment\"># Import Cloudinary libraries<\/span>\nimport cloudinary\nfrom cloudinary import uploader\nimport cloudinary.api\nfrom cloudinary.utils import cloudinary_url\n\n\n<span class=\"hljs-comment\"># Get reference to config instance<\/span>\nconfig = cloudinary.Config()\n<span class=\"hljs-keyword\">print<\/span>(config.cloud_name)\n<span class=\"hljs-keyword\">print<\/span>(config.api_key)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Step 3: Create an Upload Preset&nbsp;<\/h3>\n\n\n\n<p>You can preprocess images for deep learning in Python, unseen and in bulk, on the way into Cloudinary with just a few lines of code, so that the images you upload are ready for use.<\/p>\n\n\n\n<p>For example, you may need to reduce image size and resize all the images to fit the same dimensions. Let Cloudinary&#8217;s AI ensure that the important parts of the images aren&#8217;t cropped out. At the same time, you can convert the images to grayscale. To apply those changes, create an <a href=\"https:\/\/cloudinary.com\/documentation\/upload_presets\" target=\"_blank\" rel=\"noreferrer noopener\">Upload Preset<\/a> that pre-defines the transformations you want to use and then apply the preset to the images during the bulk upload.<\/p>\n\n\n<div class='c-callout  c-callout--inline-title c-callout--note'><strong class='c-callout__title'>Note:<\/strong> <p>This demo uses incoming transformations to change images as they\u2019re being uploaded, so that only the transformed images are saved in Cloudinary. But if you want to save the originals in your product environment, you can create variations, in addition to the original assets, by using on-the-fly transformations. To find out more, see <a href=\"https:\/\/cloudinary.com\/documentation\/transformation_reference#overview\">Image Transformations Overview<\/a>.<\/p>\n<\/div>\n\n\n<p>Let&#8217;s create the upload preset that resizes, crops, and grayscales the original cat and dog images. The transformation parameter sizes the image to a height and width of 400px. Each image is cropped while <code>\"gravity\": \"auto<\/code>&#8221; instructs Cloudinary\u2019s AI to identify the most important part of the image and make sure it\u2019s kept in the crop. To convert the image to black and white, use <code>\"effect\": \"grayscale<\/code>&#8220;.&nbsp;<\/p>\n\n\n\n<p>You have to run this code only once. Once you\u2019ve created your upload preset, it\u2019s saved in your product environment, and you can call it during any subsequent upload.<\/p>\n\n\n\n<p>Copy and paste this code snippet to your <code>animals.py<\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">cloudinary.api.create_upload_preset(\n name = <span class=\"hljs-string\">\"pre-process\"<\/span>,\n unsigned = <span class=\"hljs-keyword\">True<\/span>, \n transformation = {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>, <span class=\"hljs-string\">\"effect\"<\/span>: <span class=\"hljs-string\">\"grayscale\"<\/span>}\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Step 4: Uploading Preprocessed Images<\/h3>\n\n\n\n<p>You\u2019re now ready to apply the upload preset to the cat and dog images, generating resized, cropped and grayscale variations, which are uploaded to Cloudinary.&nbsp;<\/p>\n\n\n\n<p>This is what the images look like before applying the upload preset and uploading:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"135\" height=\"92\" data-public-id=\"Web_Assets\/blog\/cat1-2_270500b23d\/cat1-2_270500b23d.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_135,h_92,c_scale\/f_auto,q_auto\/v1681416606\/Web_Assets\/blog\/cat1-2_270500b23d\/cat1-2_270500b23d.jpg?_i=AA\" alt=\"original cat\" class=\"wp-post-27019 wp-image-27050\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416606\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416606\/Web_Assets\/blog\/cat1-2_270500b23d\/cat1-2_270500b23d.jpg?_i=AA 1024w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416606\/Web_Assets\/blog\/cat1-2_270500b23d\/cat1-2_270500b23d.jpg?_i=AA 300w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416606\/Web_Assets\/blog\/cat1-2_270500b23d\/cat1-2_270500b23d.jpg?_i=AA 768w\" sizes=\"auto, (max-width: 135px) 100vw, 135px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"199\" height=\"112\" data-public-id=\"Web_Assets\/blog\/dog2-3_270534e26c\/dog2-3_270534e26c.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_199,h_112,c_scale\/f_auto,q_auto\/v1681416599\/Web_Assets\/blog\/dog2-3_270534e26c\/dog2-3_270534e26c.jpg?_i=AA\" alt=\"original dog\" class=\"wp-post-27019 wp-image-27053\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416599\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416599\/Web_Assets\/blog\/dog2-3_270534e26c\/dog2-3_270534e26c.jpg?_i=AA 960w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416599\/Web_Assets\/blog\/dog2-3_270534e26c\/dog2-3_270534e26c.jpg?_i=AA 300w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416599\/Web_Assets\/blog\/dog2-3_270534e26c\/dog2-3_270534e26c.jpg?_i=AA 768w\" sizes=\"auto, (max-width: 199px) 100vw, 199px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"124\" height=\"124\" data-public-id=\"Web_Assets\/blog\/dog3-3_27052ff535\/dog3-3_27052ff535.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_124,h_124,c_fill,g_auto\/f_auto,q_auto\/v1681416602\/Web_Assets\/blog\/dog3-3_27052ff535\/dog3-3_27052ff535.jpg?_i=AA\" alt=\"original dog\" class=\"wp-post-27019 wp-image-27052\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416602\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416602\/Web_Assets\/blog\/dog3-3_27052ff535\/dog3-3_27052ff535.jpg?_i=AA 526w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416602\/Web_Assets\/blog\/dog3-3_27052ff535\/dog3-3_27052ff535.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416602\/Web_Assets\/blog\/dog3-3_27052ff535\/dog3-3_27052ff535.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 124px) 100vw, 124px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img width=\"1024\" height=\"921\" data-public-id=\"Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_1024,h_921,c_scale\/f_auto,q_auto\/v1681416589\/Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg?_i=AA\" alt=\"original cat\" class=\"wp-post-27019 wp-image-27054\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416589\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416589\/Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg?_i=AA 3336w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416589\/Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg?_i=AA 300w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416589\/Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg?_i=AA 768w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416589\/Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg?_i=AA 1024w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416589\/Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg?_i=AA 1536w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416589\/Web_Assets\/blog\/cat2-3_2705403582\/cat2-3_2705403582.jpg?_i=AA 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Copy and paste this code snippet to your <code>animal.py<\/code> file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-keyword\">for<\/span> x in range(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">5<\/span>):\n cat_num=<span class=\"hljs-string\">\"cat\"<\/span>+str(x)\n cat_url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+<span class=\"hljs-string\">\"cat\"<\/span>+str(x)\n dog_num=<span class=\"hljs-string\">\"dog\"<\/span>+str(x)\n dog_url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+<span class=\"hljs-string\">\"dog\"<\/span>+str(x)\n resp_cat = cloudinary.uploader.upload(cat_url, public_id = cat_num, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>, upload_preset = <span class=\"hljs-string\">\"pre-process\"<\/span>)\n <span class=\"hljs-keyword\">print<\/span>(resp_cat)\n resp_dog=cloudinary.uploader.upload(dog_url, public_id = dog_num, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>, upload_preset = <span class=\"hljs-string\">\"pre-process\"<\/span>)\n <span class=\"hljs-keyword\">print<\/span>(resp_dog)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And here is how your smartly cropped, resized, grayscaled images will look after upload:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"118\" height=\"118\" data-public-id=\"Web_Assets\/blog\/cat1-3_27055f6891\/cat1-3_27055f6891.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_118,h_118,c_fill,g_auto\/f_auto,q_auto\/v1681416586\/Web_Assets\/blog\/cat1-3_27055f6891\/cat1-3_27055f6891.jpg?_i=AA\" alt=\"grayscale cat\" class=\"wp-post-27019 wp-image-27055\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416586\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416586\/Web_Assets\/blog\/cat1-3_27055f6891\/cat1-3_27055f6891.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416586\/Web_Assets\/blog\/cat1-3_27055f6891\/cat1-3_27055f6891.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416586\/Web_Assets\/blog\/cat1-3_27055f6891\/cat1-3_27055f6891.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 118px) 100vw, 118px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"122\" height=\"122\" data-public-id=\"Web_Assets\/blog\/dog2-4_2705649d09\/dog2-4_2705649d09.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_122,h_122,c_fill,g_auto\/f_auto,q_auto\/v1681416583\/Web_Assets\/blog\/dog2-4_2705649d09\/dog2-4_2705649d09.jpg?_i=AA\" alt=\"grayscale dog\" class=\"wp-post-27019 wp-image-27056\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416583\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416583\/Web_Assets\/blog\/dog2-4_2705649d09\/dog2-4_2705649d09.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416583\/Web_Assets\/blog\/dog2-4_2705649d09\/dog2-4_2705649d09.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416583\/Web_Assets\/blog\/dog2-4_2705649d09\/dog2-4_2705649d09.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 122px) 100vw, 122px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"125\" height=\"125\" data-public-id=\"Web_Assets\/blog\/dog3-4_27057ed8e0\/dog3-4_27057ed8e0.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_125,h_125,c_fill,g_auto\/f_auto,q_auto\/v1681416579\/Web_Assets\/blog\/dog3-4_27057ed8e0\/dog3-4_27057ed8e0.jpg?_i=AA\" alt=\"grayscale dog\" class=\"wp-post-27019 wp-image-27057\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416579\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416579\/Web_Assets\/blog\/dog3-4_27057ed8e0\/dog3-4_27057ed8e0.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416579\/Web_Assets\/blog\/dog3-4_27057ed8e0\/dog3-4_27057ed8e0.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416579\/Web_Assets\/blog\/dog3-4_27057ed8e0\/dog3-4_27057ed8e0.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 125px) 100vw, 125px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"125\" height=\"125\" data-public-id=\"Web_Assets\/blog\/cat2-4_27058ed795\/cat2-4_27058ed795.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_125,h_125,c_fill,g_auto\/f_auto,q_auto\/v1681416576\/Web_Assets\/blog\/cat2-4_27058ed795\/cat2-4_27058ed795.jpg?_i=AA\" alt=\"grayscale cat\" class=\"wp-post-27019 wp-image-27058\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416576\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416576\/Web_Assets\/blog\/cat2-4_27058ed795\/cat2-4_27058ed795.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416576\/Web_Assets\/blog\/cat2-4_27058ed795\/cat2-4_27058ed795.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416576\/Web_Assets\/blog\/cat2-4_27058ed795\/cat2-4_27058ed795.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 125px) 100vw, 125px\" \/><\/figure>\n\n\n\n<p>The advantage of upload presets is that they can be reused over and over again. If you want to do a one-off, you can specify a transformation directly within the upload call, which might be a bit shorter than using an upload preset.&nbsp;<\/p>\n\n\n\n<p>Let\u2019s see how to do that while uploading one of the original images with the smart crop and resize, but without the grayscaling:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-keyword\">for<\/span> x in range(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">3<\/span>):\n cat_num=<span class=\"hljs-string\">\"cat\"<\/span>+str(x)\ncat_url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+<span class=\"hljs-string\">\"cat\"<\/span>+str(x)\n resp = cloudinary.uploader\\\n .upload(url, public_id = id, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>,\n   transformation = {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>})\n <span class=\"hljs-keyword\">print<\/span>(resp)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Notice the two additional images in your product environment:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"113\" height=\"113\" data-public-id=\"Web_Assets\/blog\/cat1_orig_resized_270590765c\/cat1_orig_resized_270590765c.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_113,h_113,c_fill,g_auto\/f_auto,q_auto\/v1681416573\/Web_Assets\/blog\/cat1_orig_resized_270590765c\/cat1_orig_resized_270590765c.jpg?_i=AA\" alt=\"preprocessing images for deep learning: original resized cat\" class=\"wp-post-27019 wp-image-27059\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416573\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416573\/Web_Assets\/blog\/cat1_orig_resized_270590765c\/cat1_orig_resized_270590765c.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416573\/Web_Assets\/blog\/cat1_orig_resized_270590765c\/cat1_orig_resized_270590765c.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416573\/Web_Assets\/blog\/cat1_orig_resized_270590765c\/cat1_orig_resized_270590765c.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 113px) 100vw, 113px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"119\" height=\"119\" data-public-id=\"Web_Assets\/blog\/cat2_orig_resized_27060e1f03\/cat2_orig_resized_27060e1f03.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_119,h_119,c_fill,g_auto\/f_auto,q_auto\/v1681416570\/Web_Assets\/blog\/cat2_orig_resized_27060e1f03\/cat2_orig_resized_27060e1f03.jpg?_i=AA\" alt=\"preprocessing images for deep learning: original resized cat\" class=\"wp-post-27019 wp-image-27060\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416570\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416570\/Web_Assets\/blog\/cat2_orig_resized_27060e1f03\/cat2_orig_resized_27060e1f03.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416570\/Web_Assets\/blog\/cat2_orig_resized_27060e1f03\/cat2_orig_resized_27060e1f03.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416570\/Web_Assets\/blog\/cat2_orig_resized_27060e1f03\/cat2_orig_resized_27060e1f03.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 119px) 100vw, 119px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Automatically Augment Images in Your Dataset<\/h3>\n\n\n\n<p>If your dataset contains hundreds of images, you\u2019ll have to increase that number to tens of thousands in order to properly train a machine learning model for accuracy. The good news is to get more data, you don\u2019t need to produce new original images; you simply need to make minor changes, like flipping or rotating, to your current dataset and load the variations as distinct images.&nbsp;<\/p>\n\n\n\n<p>Transforming images to create copies modified-to-order is Cloudinary\u2019s forte! Cloudinary can automatically augment your images by applying transformations, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#saturation\">Saturation<\/a><\/li>\n\n\n\n<li><a href=\"#rotation\">Rotation<\/a><\/li>\n\n\n\n<li><a href=\"#flipping\">Flipping<\/a><\/li>\n\n\n\n<li><a href=\"#colorization\">Colorization<\/a><\/li>\n\n\n\n<li><a href=\"#contrast\">Contrast<\/a><\/li>\n\n\n\n<li><a href=\"#brightness\">Brightness<\/a><\/li>\n<\/ul>\n\n\n\n<p>\u2026and much much more.<\/p>\n\n\n\n<p>Let\u2019s see how to apply each augmentation to selected original cat and dog images.&nbsp;<\/p>\n\n\n\n<p>First, the images are resized and cropped as required, and then the Cloudinary transformation is applied to create an augmented copy, which is uploaded as an additional, distinct original in the dataset.<\/p>\n\n\n\n<p>Copy and paste each code snippet to your <code>animal.py<\/code> file:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Saturation<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># Saturation<\/span>\n<span class=\"hljs-comment\"># Adjust the image saturation to 70:<\/span>\n\n\n<span class=\"hljs-keyword\">for<\/span> x in range(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">3<\/span>):\n id=<span class=\"hljs-string\">\"dog\"<\/span> + str(x) + <span class=\"hljs-string\">\"_saturated\"<\/span>\n url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+<span class=\"hljs-string\">\"dog\"<\/span>+str(x)\n resp = cloudinary.uploader\\\n .upload(url, public_id = id, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>,\n   transformation = {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>, <span class=\"hljs-string\">\"effect\"<\/span>: <span class=\"hljs-string\">\"saturation:70\"<\/span>})\n <span class=\"hljs-keyword\">print<\/span>(resp)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here\u2019s how the resulting images appear:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"133\" height=\"133\" data-public-id=\"Web_Assets\/blog\/dog1_saturated_270615d5c6\/dog1_saturated_270615d5c6.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_133,h_133,c_fill,g_auto\/f_auto,q_auto\/v1681416567\/Web_Assets\/blog\/dog1_saturated_270615d5c6\/dog1_saturated_270615d5c6.jpg?_i=AA\" alt=\"preprocessing images for deep learning: saturated dog\" class=\"wp-post-27019 wp-image-27061\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416567\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416567\/Web_Assets\/blog\/dog1_saturated_270615d5c6\/dog1_saturated_270615d5c6.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416567\/Web_Assets\/blog\/dog1_saturated_270615d5c6\/dog1_saturated_270615d5c6.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416567\/Web_Assets\/blog\/dog1_saturated_270615d5c6\/dog1_saturated_270615d5c6.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 133px) 100vw, 133px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"135\" height=\"135\" data-public-id=\"Web_Assets\/blog\/dog2_saturated_27062ae5e6\/dog2_saturated_27062ae5e6.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_135,h_135,c_fill,g_auto\/f_auto,q_auto\/v1681416564\/Web_Assets\/blog\/dog2_saturated_27062ae5e6\/dog2_saturated_27062ae5e6.jpg?_i=AA\" alt=\"preprocessing images for deep learning: saturated dog\" class=\"wp-post-27019 wp-image-27062\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416564\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416564\/Web_Assets\/blog\/dog2_saturated_27062ae5e6\/dog2_saturated_27062ae5e6.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416564\/Web_Assets\/blog\/dog2_saturated_27062ae5e6\/dog2_saturated_27062ae5e6.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416564\/Web_Assets\/blog\/dog2_saturated_27062ae5e6\/dog2_saturated_27062ae5e6.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 135px) 100vw, 135px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Rotation<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># Rotate<\/span>\n<span class=\"hljs-comment\"># Rotate the images 10 degrees to the right:<\/span>\n\n\n<span class=\"hljs-keyword\">for<\/span> x in range(<span class=\"hljs-number\">3<\/span>,<span class=\"hljs-number\">5<\/span>):\n id=<span class=\"hljs-string\">\"dog\"<\/span> + str(x) + <span class=\"hljs-string\">\"_rotated\"<\/span>\n url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+<span class=\"hljs-string\">\"dog\"<\/span>+str(x)\n resp = cloudinary.uploader\\\n .upload(url, public_id = id, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>,\n   transformation = &#91;{ <span class=\"hljs-string\">\"angle\"<\/span>: <span class=\"hljs-number\">10<\/span>}, {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>}]\n )\n <span class=\"hljs-keyword\">print<\/span>(resp)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here\u2019s how the resulting images appear:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"132\" height=\"132\" data-public-id=\"Web_Assets\/blog\/dog3_rotated_270632102b\/dog3_rotated_270632102b.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_132,h_132,c_fill,g_auto\/f_auto,q_auto\/v1681416562\/Web_Assets\/blog\/dog3_rotated_270632102b\/dog3_rotated_270632102b.jpg?_i=AA\" alt=\"preprocessing images for deep learning: rotated dog\" class=\"wp-post-27019 wp-image-27063\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416562\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416562\/Web_Assets\/blog\/dog3_rotated_270632102b\/dog3_rotated_270632102b.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416562\/Web_Assets\/blog\/dog3_rotated_270632102b\/dog3_rotated_270632102b.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416562\/Web_Assets\/blog\/dog3_rotated_270632102b\/dog3_rotated_270632102b.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 132px) 100vw, 132px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"119\" height=\"119\" data-public-id=\"Web_Assets\/blog\/dog4_rotated_27064a66a0\/dog4_rotated_27064a66a0.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_119,h_119,c_fill,g_auto\/f_auto,q_auto\/v1681416559\/Web_Assets\/blog\/dog4_rotated_27064a66a0\/dog4_rotated_27064a66a0.jpg?_i=AA\" alt=\"preprocessing images for deep learning: rotated dog\" class=\"wp-post-27019 wp-image-27064\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416559\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416559\/Web_Assets\/blog\/dog4_rotated_27064a66a0\/dog4_rotated_27064a66a0.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416559\/Web_Assets\/blog\/dog4_rotated_27064a66a0\/dog4_rotated_27064a66a0.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416559\/Web_Assets\/blog\/dog4_rotated_27064a66a0\/dog4_rotated_27064a66a0.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 119px) 100vw, 119px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Flipping<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># Flip<\/span>\n<span class=\"hljs-comment\"># Flip the images horizontally:<\/span>\n\n\nanimal=&#91;<span class=\"hljs-string\">\"dog\"<\/span>,<span class=\"hljs-string\">\"cat\"<\/span>]\n<span class=\"hljs-keyword\">for<\/span> x in range(<span class=\"hljs-number\">2<\/span>,<span class=\"hljs-number\">4<\/span>):\n id=animal&#91;x<span class=\"hljs-number\">-2<\/span>] + str(x) + <span class=\"hljs-string\">\"_flipped\"<\/span>\n url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+animal&#91;x<span class=\"hljs-number\">-2<\/span>]+str(x)\n resp = cloudinary.uploader\\\n .upload(url, public_id = id, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>,\n   transformation = &#91;{ <span class=\"hljs-string\">\"angle\"<\/span>: &#91;<span class=\"hljs-string\">\"vflip\"<\/span>, <span class=\"hljs-number\">180<\/span>]}, {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>}]\n )\n <span class=\"hljs-keyword\">print<\/span>(resp)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here\u2019s how the resulting images appear:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"134\" height=\"134\" data-public-id=\"Web_Assets\/blog\/cat3_flipped_27065c1f68\/cat3_flipped_27065c1f68.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_134,h_134,c_fill,g_auto\/f_auto,q_auto\/v1681416556\/Web_Assets\/blog\/cat3_flipped_27065c1f68\/cat3_flipped_27065c1f68.jpg?_i=AA\" alt=\"preprocessing images for deep learning: flipped cat\" class=\"wp-post-27019 wp-image-27065\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416556\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416556\/Web_Assets\/blog\/cat3_flipped_27065c1f68\/cat3_flipped_27065c1f68.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416556\/Web_Assets\/blog\/cat3_flipped_27065c1f68\/cat3_flipped_27065c1f68.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416556\/Web_Assets\/blog\/cat3_flipped_27065c1f68\/cat3_flipped_27065c1f68.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 134px) 100vw, 134px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"141\" height=\"141\" data-public-id=\"Web_Assets\/blog\/dog2_flipped_27066e594b\/dog2_flipped_27066e594b.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_141,h_141,c_fill,g_auto\/f_auto,q_auto\/v1681416554\/Web_Assets\/blog\/dog2_flipped_27066e594b\/dog2_flipped_27066e594b.jpg?_i=AA\" alt=\"preprocessing images for deep learning: flipped dog\" class=\"wp-post-27019 wp-image-27066\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416554\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416554\/Web_Assets\/blog\/dog2_flipped_27066e594b\/dog2_flipped_27066e594b.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416554\/Web_Assets\/blog\/dog2_flipped_27066e594b\/dog2_flipped_27066e594b.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416554\/Web_Assets\/blog\/dog2_flipped_27066e594b\/dog2_flipped_27066e594b.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 141px) 100vw, 141px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Colorization<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># Colorize<\/span>\n<span class=\"hljs-comment\"># Colorize the images with a green effect:<\/span>\n\n\n<span class=\"hljs-keyword\">for<\/span> x in range(<span class=\"hljs-number\">1<\/span>,<span class=\"hljs-number\">3<\/span>):\n id=<span class=\"hljs-string\">\"cat\"<\/span> + str(x) + <span class=\"hljs-string\">\"_colorized\"<\/span>\n url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+<span class=\"hljs-string\">\"cat\"<\/span>+str(x)\n resp = cloudinary.uploader\\\n .upload(url, public_id = id, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>,\n   transformation = {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>, <span class=\"hljs-string\">\"color\"<\/span>: <span class=\"hljs-string\">\"#20a020\"<\/span>, <span class=\"hljs-string\">\"effect\"<\/span>: <span class=\"hljs-string\">\"colorize:50\"<\/span>}\n )\n <span class=\"hljs-keyword\">print<\/span>(resp)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here\u2019s how the resulting images appear:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"128\" height=\"128\" data-public-id=\"Web_Assets\/blog\/cat1_colorized_2706763130\/cat1_colorized_2706763130.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_128,h_128,c_fill,g_auto\/f_auto,q_auto\/v1681416551\/Web_Assets\/blog\/cat1_colorized_2706763130\/cat1_colorized_2706763130.jpg?_i=AA\" alt=\"preprocessing images for deep learning: colorized cat\" class=\"wp-post-27019 wp-image-27067\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416551\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416551\/Web_Assets\/blog\/cat1_colorized_2706763130\/cat1_colorized_2706763130.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416551\/Web_Assets\/blog\/cat1_colorized_2706763130\/cat1_colorized_2706763130.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416551\/Web_Assets\/blog\/cat1_colorized_2706763130\/cat1_colorized_2706763130.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 128px) 100vw, 128px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"136\" height=\"136\" data-public-id=\"Web_Assets\/blog\/cat2_colorized_27068f046c\/cat2_colorized_27068f046c.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_136,h_136,c_fill,g_auto\/f_auto,q_auto\/v1681416548\/Web_Assets\/blog\/cat2_colorized_27068f046c\/cat2_colorized_27068f046c.jpg?_i=AA\" alt=\"preprocessing images for deep learning: colorized cat\" class=\"wp-post-27019 wp-image-27068\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416548\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416548\/Web_Assets\/blog\/cat2_colorized_27068f046c\/cat2_colorized_27068f046c.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416548\/Web_Assets\/blog\/cat2_colorized_27068f046c\/cat2_colorized_27068f046c.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416548\/Web_Assets\/blog\/cat2_colorized_27068f046c\/cat2_colorized_27068f046c.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 136px) 100vw, 136px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Contrast<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># Contrast<\/span>\n<span class=\"hljs-comment\"># Automatically adjust the contrast and apply an 80% blend:<\/span>\n\n\n<span class=\"hljs-keyword\">for<\/span> x in range(<span class=\"hljs-number\">3<\/span>,<span class=\"hljs-number\">5<\/span>):\n id=<span class=\"hljs-string\">\"cat\"<\/span> + str(x) + <span class=\"hljs-string\">\"_contrasted\"<\/span>\n url=<span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+<span class=\"hljs-string\">\"cat\"<\/span>+str(x)\n resp = cloudinary.uploader\\\n .upload(url, public_id = id, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>,\n   transformation = {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>, <span class=\"hljs-string\">\"effect\"<\/span>: <span class=\"hljs-string\">\"auto_contrast:80\"<\/span>}\n )\n <span class=\"hljs-keyword\">print<\/span>(resp)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here\u2019s how the resulting images appear:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"144\" height=\"144\" data-public-id=\"Web_Assets\/blog\/cat3_contrasted_27069e386d\/cat3_contrasted_27069e386d.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_144,h_144,c_fill,g_auto\/f_auto,q_auto\/v1681416545\/Web_Assets\/blog\/cat3_contrasted_27069e386d\/cat3_contrasted_27069e386d.jpg?_i=AA\" alt=\"preprocessing images for deep learning: contrast cat\" class=\"wp-post-27019 wp-image-27069\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416545\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416545\/Web_Assets\/blog\/cat3_contrasted_27069e386d\/cat3_contrasted_27069e386d.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416545\/Web_Assets\/blog\/cat3_contrasted_27069e386d\/cat3_contrasted_27069e386d.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416545\/Web_Assets\/blog\/cat3_contrasted_27069e386d\/cat3_contrasted_27069e386d.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 144px) 100vw, 144px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"140\" height=\"140\" data-public-id=\"Web_Assets\/blog\/cat4_contrasted_270707333e\/cat4_contrasted_270707333e.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_140,h_140,c_fill,g_auto\/f_auto,q_auto\/v1681416542\/Web_Assets\/blog\/cat4_contrasted_270707333e\/cat4_contrasted_270707333e.jpg?_i=AA\" alt=\"preprocessing images for deep learning: contrast cat\" class=\"wp-post-27019 wp-image-27070\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416542\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416542\/Web_Assets\/blog\/cat4_contrasted_270707333e\/cat4_contrasted_270707333e.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416542\/Web_Assets\/blog\/cat4_contrasted_270707333e\/cat4_contrasted_270707333e.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416542\/Web_Assets\/blog\/cat4_contrasted_270707333e\/cat4_contrasted_270707333e.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 140px) 100vw, 140px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Brightness<\/h3>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\"><span class=\"hljs-comment\"># Bright<\/span>\n<span class=\"hljs-comment\"># Adjust the image brightness to 60:<\/span>\n\n\nanimal=&#91;<span class=\"hljs-string\">\"dog\"<\/span>,<span class=\"hljs-string\">\"cat\"<\/span>]\n<span class=\"hljs-keyword\">for<\/span> a in animal:\n id= a + <span class=\"hljs-string\">\"1\"<\/span> + <span class=\"hljs-string\">\"_brightness\"<\/span>\n url= <span class=\"hljs-string\">\"https:\/\/res.cloudinary.com\/demo\/image\/upload\/v1\/blogs\/python-preprocessing\/\"<\/span>+a+<span class=\"hljs-string\">\"1\"<\/span>\n resp = cloudinary.uploader\\\n .upload(url, public_id = id, unique_filename = <span class=\"hljs-keyword\">False<\/span>, overwrite = <span class=\"hljs-keyword\">True<\/span>,\n   transformation = {<span class=\"hljs-string\">\"width\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"height\"<\/span>: <span class=\"hljs-number\">400<\/span>, <span class=\"hljs-string\">\"crop\"<\/span>: <span class=\"hljs-string\">\"fill\"<\/span>, <span class=\"hljs-string\">\"gravity\"<\/span>: <span class=\"hljs-string\">\"auto\"<\/span>, <span class=\"hljs-string\">\"effect\"<\/span>: <span class=\"hljs-string\">\"brightness:60\"<\/span>}\n )\n <span class=\"hljs-keyword\">print<\/span>(resp)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here\u2019s how the resulting images appear:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"148\" height=\"148\" data-public-id=\"Web_Assets\/blog\/cat1_brightness_270715f192\/cat1_brightness_270715f192.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_148,h_148,c_fill,g_auto\/f_auto,q_auto\/v1681416539\/Web_Assets\/blog\/cat1_brightness_270715f192\/cat1_brightness_270715f192.jpg?_i=AA\" alt=\"preprocessing images for deep learning: bright cat\" class=\"wp-post-27019 wp-image-27071\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416539\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416539\/Web_Assets\/blog\/cat1_brightness_270715f192\/cat1_brightness_270715f192.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416539\/Web_Assets\/blog\/cat1_brightness_270715f192\/cat1_brightness_270715f192.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416539\/Web_Assets\/blog\/cat1_brightness_270715f192\/cat1_brightness_270715f192.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 148px) 100vw, 148px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img width=\"148\" height=\"148\" data-public-id=\"Web_Assets\/blog\/dog1_brightness_270723dc4d\/dog1_brightness_270723dc4d.jpg\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/w_148,h_148,c_fill,g_auto\/f_auto,q_auto\/v1681416536\/Web_Assets\/blog\/dog1_brightness_270723dc4d\/dog1_brightness_270723dc4d.jpg?_i=AA\" alt=\"preprocessing images for deep learning: bright dog\" class=\"wp-post-27019 wp-image-27072\" data-format=\"jpg\" data-transformations=\"f_auto,q_auto\" data-version=\"1681416536\" data-seo=\"1\" srcset=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416536\/Web_Assets\/blog\/dog1_brightness_270723dc4d\/dog1_brightness_270723dc4d.jpg?_i=AA 400w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416536\/Web_Assets\/blog\/dog1_brightness_270723dc4d\/dog1_brightness_270723dc4d.jpg?_i=AA 150w, https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681416536\/Web_Assets\/blog\/dog1_brightness_270723dc4d\/dog1_brightness_270723dc4d.jpg?_i=AA 300w\" sizes=\"auto, (max-width: 148px) 100vw, 148px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Step 6: Run Your Code<\/h3>\n\n\n\n<p>And that\u2019s how to write your first program to preprocess images for deep learning in Python, using Cloudinary! If you\u2019ve been copying and pasting these code snippets to your <code>animal.py<\/code> file, you can run it now. Check out your product environment and see all the images you\u2019ve just uploaded.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Explore Cloudinary\u2019s Additional Powerful Features<\/h2>\n\n\n\n<p>This demo has shown you just some of Cloudinary\u2019s many powerful features. Another useful feature is <a href=\"https:\/\/cloudinary.com\/documentation\/cloudinary_add_ons\" target=\"_blank\" rel=\"noreferrer noopener\">automatic classification and tagging<\/a>. Hand the task of manually sorting and labeling over to Cloudinary, and you\u2019ll save an inordinate amount of time and manpower. Automatic classification and tagging empowers you to easily retrieve unseen images by tag and manage them accordingly.<\/p>\n\n\n\n<p>Dive deeper into Cloudinary\u2019s capabilities:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Discover the vast collection of <a href=\"https:\/\/cloudinary.com\/documentation\/transformation_reference\" target=\"_blank\" rel=\"noreferrer noopener\">image transformations<\/a> you can apply<\/li>\n\n\n\n<li>Learn about the gamut of <a href=\"https:\/\/cloudinary.com\/documentation\/media_optimization\" target=\"_blank\" rel=\"noreferrer noopener\">image optimization<\/a>&nbsp;possibilities for delivery over the web&nbsp;<\/li>\n\n\n\n<li>Find out about the myriad of options for <a href=\"https:\/\/cloudinary.com\/documentation\/managing_assets\" target=\"_blank\" rel=\"noreferrer noopener\">managing images<\/a>.&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>For more than a decade, Cloudinary has been a leader in image management, used to streamline a variety of business workflows. Like any great tool, Cloudinary is versatile and can apply to all sorts of different use cases, including yours. It\u2019s a perfect complement to your out-of-the-box thinking.&nbsp;<\/p>\n\n\n\n<p>With its rich AI capabilities, Cloudinary can normalize and augment the images you use to train learning models with just a few lines of code. Why not try Cloudinary as one of your tools to automatically preprocess images for deep learning in Python? Start using Cloudinary and let us know how you\u2019ve become more efficient as a result. <a href=\"https:\/\/community.cloudinary.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Join the discussion<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a data scientist, you likely use images for model training and inference. But before they\u2019re ready for you to use, images must undergo a set of transformations. This is called image preprocessing.&nbsp; Why would you need to preprocess your images? Image preprocessing can have major positive impacts on the neural networks you\u2019re training, including:&nbsp; [&hellip;]<\/p>\n","protected":false},"author":52,"featured_media":27118,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-27019","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Better Preprocess Images for Deep Learning in Python<\/title>\n<meta name=\"description\" content=\"Learn a new tool to better preprocess images for deep learning using Python. Cloudinary provides AI capabilities to do it for you, in bulk.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Better Preprocess Images for Deep Learning in Python\" \/>\n<meta property=\"og:description\" content=\"Learn a new tool to better preprocess images for deep learning using Python. Cloudinary provides AI capabilities to do it for you, in bulk.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-14T14:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-16T10:22:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python-jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"sharonyelenik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python\"},\"author\":{\"name\":\"sharonyelenik\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/dc4e70df8d22a9cfdad676a82fa92a73\"},\"headline\":\"How to Better Preprocess Images for Deep Learning in Python\",\"datePublished\":\"2023-02-14T14:00:00+00:00\",\"dateModified\":\"2025-02-16T10:22:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python\"},\"wordCount\":1482,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA\",\"inLanguage\":\"en-US\",\"copyrightYear\":\"2023\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python\",\"url\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python\",\"name\":\"How to Better Preprocess Images for Deep Learning in Python\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA\",\"datePublished\":\"2023-02-14T14:00:00+00:00\",\"dateModified\":\"2025-02-16T10:22:30+00:00\",\"description\":\"Learn a new tool to better preprocess images for deep learning using Python. Cloudinary provides AI capabilities to do it for you, in bulk.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA\",\"width\":2000,\"height\":1100},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Better Preprocess Images for Deep Learning in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/dc4e70df8d22a9cfdad676a82fa92a73\",\"name\":\"sharonyelenik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6565cdd768a04e9b6ea3932764886209dd9de8baeeef1504eaad8fe776677f92?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6565cdd768a04e9b6ea3932764886209dd9de8baeeef1504eaad8fe776677f92?s=96&d=mm&r=g\",\"caption\":\"sharonyelenik\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Better Preprocess Images for Deep Learning in Python","description":"Learn a new tool to better preprocess images for deep learning using Python. Cloudinary provides AI capabilities to do it for you, in bulk.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python","og_locale":"en_US","og_type":"article","og_title":"How to Better Preprocess Images for Deep Learning in Python","og_description":"Learn a new tool to better preprocess images for deep learning using Python. Cloudinary provides AI capabilities to do it for you, in bulk.","og_url":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python","og_site_name":"Cloudinary Blog","article_published_time":"2023-02-14T14:00:00+00:00","article_modified_time":"2025-02-16T10:22:30+00:00","og_image":[{"width":2000,"height":1100,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python-jpg?_i=AA","type":"image\/jpeg"}],"author":"sharonyelenik","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python"},"author":{"name":"sharonyelenik","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/dc4e70df8d22a9cfdad676a82fa92a73"},"headline":"How to Better Preprocess Images for Deep Learning in Python","datePublished":"2023-02-14T14:00:00+00:00","dateModified":"2025-02-16T10:22:30+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python"},"wordCount":1482,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA","inLanguage":"en-US","copyrightYear":"2023","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python","url":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python","name":"How to Better Preprocess Images for Deep Learning in Python","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA","datePublished":"2023-02-14T14:00:00+00:00","dateModified":"2025-02-16T10:22:30+00:00","description":"Learn a new tool to better preprocess images for deep learning using Python. Cloudinary provides AI capabilities to do it for you, in bulk.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA","width":2000,"height":1100},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/preprocess-images-for-deep-learning-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Better Preprocess Images for Deep Learning in Python"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/dc4e70df8d22a9cfdad676a82fa92a73","name":"sharonyelenik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6565cdd768a04e9b6ea3932764886209dd9de8baeeef1504eaad8fe776677f92?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6565cdd768a04e9b6ea3932764886209dd9de8baeeef1504eaad8fe776677f92?s=96&d=mm&r=g","caption":"sharonyelenik"}}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1675201980\/blog-preprocessing_python\/blog-preprocessing_python.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/27019","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/52"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=27019"}],"version-history":[{"count":25,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/27019\/revisions"}],"predecessor-version":[{"id":36826,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/27019\/revisions\/36826"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/27118"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=27019"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=27019"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=27019"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}