-1

Was facing an issue in classification model trained on fastai.

Running images in batches on a classification model. But due to 1 image, entire batch is failing. The classification model when trained was trained on preprocessed images, by applying transformations on image size = 224. When the particular image is passed through, it shows this error and entire batch fails.

"Image size (324768098) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack."

Why is this error showing then?

Had preprocessed the images when I trained the model, by providing image size to be 224.

I'd like to respect the limit and not increase the limit (as described here: Pillow in Python won't let me open image ("exceeds limit"))

How can I load it in a way that the resolution is lowered just below the limit and the lower resolution image is referenced in img without causing any error.

It'd be great to have a Python solution but if not, any other solution will work too.

  • basically running images in batches on a classification model. But due to 1 image, entire batch is failing. The classification model when trained was trained on preprocessed images, by applying transformations on image size = 224. When the particular image is passed through, it shows this error and entire batch fails. I dont want to bypass this security feature by PIL, but is there any other way that I can reduce the pixel/resolution of the image to process them? – Arastu Mudgal Jan 18 '23 at 04:08

1 Answers1

0

For those who have encountered a similar problem but don't mind fixing the code: find …/PIL/image.py and patch it:

$ diff -b -C 3 Image.py- Image.py
*** Image.py-   Sat Apr 15 16:11:17 2023
--- Image.py    Sat Apr 15 19:20:14 2023
***************
*** 91,97 ****
  
  
  # Limit to around a quarter gigabyte for a 24-bit (3 bpp) image
! MAX_IMAGE_PIXELS = int(1024 * 1024 * 1024 // 4 // 3)
  
  
  try:
--- 91,97 ----
  
  
  # Limit to around a quarter gigabyte for a 24-bit (3 bpp) image
! MAX_IMAGE_PIXELS = int(8192 * 8192 * 8192 // 4 // 3)
  
  
  try:
Serge Ivamov
  • 304
  • 2
  • 7