I am trying to figure out ImageAI and I followed their documentation here exactly - it's a model to predict what is in a picture. But when I run my script in the terminal I get the below error. I've searched online but all the answers I see are in relation to specifying the encoding but I can't see any way to do that here. I'd appreciate any help I can get with sorting out this error. Thanks!

My code:

from imageai.Classification import ImageClassification
import os

execution_path = os.getcwd()

prediction = ImageClassification() 
prediction.setModelTypeAsResNet50()  # sets the model type of the prediction object to ResNet
prediction.setModelPath(os.path.join(execution_path, "resnet50-19c8e357.pth"))  # sets the model path
prediction.loadModel()  # loads the model

predictions, probabilities = prediction.classifyImage(os.path.join(execution_path, "giraffe.jpg"), result_count=5)

for eachPrediction, eachProbability in zip(predictions, probabilities):
    print(eachPrediction , " : " , eachProbability)

The error:

Fatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1176, in exec_module
  File "<frozen site>", line 614, in <module>
  File "<frozen site>", line 597, in main
  File "<frozen site>", line 529, in venv
  File "<frozen site>", line 384, in addsitepackages
  File "<frozen site>", line 226, in addsitedir
  File "<frozen site>", line 179, in addpackage
  File "C:\Users\qu\AppData\Local\Programs\Python\Python312\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1822: character maps to <undefined>

I tried changing the model and got the same error.

0

There are 0 best solutions below