Search code examples
pythonopencvpython-os

I am trying to import images and it is returning "TypeError: cannot unpack non-iterable NoneType object"


I am giving a folder path to my function but it is returning TypeError

faces, labels = prepare_training_data("C:\\Users\\prite\\Desktop\\projects\\0007\\training-data")

the error it shows is

TypeError                                 Traceback (most recent call last)
<ipython-input-13-c070ed2f52c1> in <module>
----> 1 faces, labels = prepare_training_data("C:\\Users\\prite\\Desktop\\projects\\0007\\training-data")
      2 print("Total faces: ", len(faces))
      3 print("Total labels: ", len(labels))

TypeError: cannot unpack non-iterable NoneType object

My function is:

def prepare_training_data(data_folder_path):
    dirs = os.listdir(data_folder_path)
    faces = []

Solution

  • Try add "r" before path.

    prepare_training_data(r'C:\Users\prite\Desktop\projects\0007\training-data')