lobe / lobe-python

Python toolset for working with Lobe models
MIT License
185 stars 38 forks source link

Error while predicting result #31

Open GDGauravDutta opened 2 years ago

GDGauravDutta commented 2 years ago

TypeError Traceback (most recent call last) /tmp/ipykernel_35/1784468283.py in 1 result=[] 2 for i in test.filename: ----> 3 result_i= model.predict_from_file(i) 4 result.append(result_i.prediction) 5 print(result,len(result))

/opt/conda/lib/python3.7/site-packages/lobe/model/image_model.py in predict_from_file(self, path) 58 59 def predict_from_file(self, path: str): ---> 60 return self.predict(image_utils.get_image_from_file(path)) 61 62 def predict(self, image: Image.Image) -> ClassificationResult:

/opt/conda/lib/python3.7/site-packages/lobe/model/image_model.py in predict(self, image) 61 62 def predict(self, image: Image.Image) -> ClassificationResult: ---> 63 image_processed = image_utils.preprocess_image(image, self.signature.input_image_size) 64 image_array = image_utils.image_to_array(image_processed) 65 results = self.backend.predict(image_array)

/opt/conda/lib/python3.7/site-packages/lobe/image_utils.py in preprocess_image(image, size) 83 84 def preprocess_image(image: Image.Image, size: Tuple[int, int]) -> Image.Image: ---> 85 image_processed = update_orientation(image) 86 87 # resize and crop image to the model's required size

/opt/conda/lib/python3.7/site-packages/lobe/image_utils.py in update_orientation(image) 47 exif_orientation_tag = 0x0112 48 if hasattr(image, '_getexif'): ---> 49 exif = image._getexif() 50 if exif != None and exif_orientation_tag in exif: 51 orientation = exif.get(exif_orientation_tag, 1)

/opt/conda/lib/python3.7/site-packages/PIL/JpegImagePlugin.py in _getexif(self) 473 474 def _getexif(self): --> 475 return _getexif(self) 476 477 def _getmp(self):

/opt/conda/lib/python3.7/site-packages/PIL/JpegImagePlugin.py in _getexif(self) 496 if "exif" not in self.info: 497 return None --> 498 return self.getexif()._get_merged_dict() 499 500

/opt/conda/lib/python3.7/site-packages/PIL/Image.py in getexif(self) 1322 1323 self.load() -> 1324 if band is not None: 1325 return self.im.getband(band) 1326 return self.im # could be abused

/opt/conda/lib/python3.7/site-packages/PIL/Image.py in load(self, data) 3354 atexit.register(core.clear_cache) 3355 -> 3356 3357 class Exif(MutableMapping): 3358 endian = None

/opt/conda/lib/python3.7/site-packages/PIL/TiffImagePlugin.py in load(self, fp) 774 tag, typ, count, data = self._unpack("HHL4s", self._ensure_read(fp, 12)) 775 --> 776 tagname = TiffTags.lookup(tag, self.group).name 777 typname = TYPES.get(typ, "unknown") 778 msg = f"tag: {tagname} ({tag}) - type: {typname} ({typ})"

TypeError: lookup() takes 1 positional argument but 2 were given

Kaggle : https://www.kaggle.com/gauravduttakiit/notebook52daed67ed

Originally posted by @GDGauravDutta in https://github.com/lobe/lobe-python/issues/25#issuecomment-1045846033

mbeissinger commented 2 years ago

What was the image filetype used here? It looks like a Pillow error (supported files here: https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html). Are you able to open the image file directly with Pillow by doing:

from PIL import Image
img = Image.open('path/to/file.jpg')
GDGauravDutta commented 2 years ago

Nope. Same error is populated. Can pls someone suggested to bypass this error.

Pikamander2 commented 2 years ago

/opt/conda/lib/python3.7/site-packages/PIL/TiffImagePlugin.py 776 tagname = TiffTags.lookup(tag, self.group).name TypeError: lookup() takes 1 positional argument but 2 were given

At a glance, it looks like it's related to Pillow's TIFF handler, although the documentation linked above suggests that TIFFs are supported.

Does it still happen if you remove all of the TIFF files and only use JPGs/PNGs?

GDGauravDutta commented 2 years ago

from PIL import Image img = Image.open('path/to/file.jpg')

YEs