lobe/lobe-python

Error while predicting result

Closed this issue · 3 comments


TypeError Traceback (most recent call last)
in
10 img = Image.open('./{}'.format(a))
11 print(a)
---> 12 result = model.predict(img)
13 # Print top prediction
14 print('Model Prediction : {}'.format(result.prediction))

/opt/conda/lib/python3.7/site-packages/lobe/model/image_model.py in predict(self, image)
45
46 def predict(self, image: Image.Image) -> ClassificationResult:
---> 47 image_processed = image_utils.preprocess_image(image, self.signature.input_image_size)
48 image_array = image_utils.image_to_array(image_processed)
49 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 return self.im # could be abused
1323
-> 1324 def getextrema(self):
1325 """
1326 Gets the the minimum and maximum pixel values for each band in

/opt/conda/lib/python3.7/site-packages/PIL/Image.py in load(self, data)
3354 self._data = {}
3355 self._ifds = {}
-> 3356 self._info = None
3357 self._loaded_exif = None
3358

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

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

This looks like pillow couldn't load the image -- what is the filetype?

Closing -- please comment with the filetype and if Pillow can load the image outside of Lobe. We only support what Pillow can open.

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