title: How to solve "out of memory" error in Jupyter Notebook?
body: <p>I was trying to create patches of the images from my dataset. This is my code:</p>
  <pre class="lang-py prettyprint-override"><code>for path, subdirs, files in os.walk(root_directory):  
      dirname = path.split(os.path.sep)[-1]
      if dirname == 'images':   #Find all 'images' directories
          images = os.listdir(path)  #List of all image names in this subdirectory
          for i, image_name in enumerate(images):  
              if image_name.endswith(&quot;.tif&quot;):   #Only read jpg images...
                 
                  image = cv2.imread(path+&quot;/&quot;+image_name, 1)  #Read each image as BGR
                  SIZE_X = (image.shape[1]//patch_size)*patch_size #Nearest size divisible by our patch size
                  SIZE_Y = (image.shape[0]//patch_size)*patch_size #Nearest size divisible by our patch size
                  image = Image.fromarray(image)
                  image = image.crop((0 ,0, SIZE_X, SIZE_Y))  #Crop from top left corner
                  #image = image.resize((SIZE_X, SIZE_Y))  #Try not to resize for semantic segmentation
                  image = np.array(image)             
         
                  #Extract patches from each image
                  print(&quot;Now patchifying image:&quot;, path+&quot;/&quot;+image_name)
                  patches_img = patchify(image, (patch_size, patch_size, 3), step=patch_size)  #Step=256 for 256 patches means no overlap
          
                  for i in range(patches_img.shape[0]):
                      for j in range(patches_img.shape[1]):
                          
                          single_patch_img = patches_img[i,j,:,:]
                          
                          #Use minmaxscaler instead of just dividing by 255. 
                          single_patch_img = scaler.fit_transform(single_patch_img.reshape(-1, single_patch_img.shape[-1])).reshape(single_patch_img.shape)
                          
                          #single_patch_img = (single_patch_img.astype('float32')) / 255. 
                          single_patch_img = single_patch_img[0] #Drop the extra unecessary dimension that patchify adds.                               
                          image_dataset.append(single_patch_img)
  </code></pre>
  <p>But it shows the error &quot;out of memory&quot; and immediately shuts down. I am using 32GB ram and 1660Ti GPU. The images are 5000X5000 pixels and the size of my dataset is 12.7GB.</p>