ragulin / face-recognition-server

An face recognition experiment with WebRTC, Websockets, OpenCV and Python.
215 stars 91 forks source link

After load_images_from_db, lists 'images' and 'labels' are returned empty #12

Open iamsashank09 opened 6 years ago

iamsashank09 commented 6 years ago

When I ran the program, it showed me all the info including 'saving paths..' then I encountered this error,

 OpenCV Error: Bad argument (Empty training data was given. You'll need more than one sample to learn a model.) in train, file /io/opencv_contrib/modules/face/src/fisher_faces.cpp, line 71
Traceback (most recent call last):
  File "server.py", line 121, in <module>
    main()
  File "server.py", line 114, in main
    opencv.train()
  File "/home/sashank/face-recognition-server/opencv.py", line 89, in train
    model.train(images,labels)
cv2.error: /io/opencv_contrib/modules/face/src/fisher_faces.cpp:71: error: (-5) Empty training data was given. You'll need more than one sample to learn a model. in function train

Turns out, the images and labels lists are empty. Checked the 'load_images_from_db()' function and I figured that this code, doesn't even run -

try:
        cv_image = cv2.imread(image.path, cv2.IMREAD_GRAYSCALE)
        cv_image = cv2.resize(cv_image, (100,100))
        images.append(np.asarray(cv_image, dtype=np.uint8))
        labels.append(label.id)
      except IOError, (errno, strerror):
       print "IOError({0}): {1}".format(errno, strerror)

That's because it isn't entering the for image in label.image_set: loop!

I have no idea whats wrong and I'm struggling with this from a long time. The only changes I made to the original code are, Changed label.save() to label[0].save() and image.save() to image[0].save() since I was encountering the

image.save()
AttributeError: 'tuple' object has no attribute 'save'

and image = Image.get_or_create(path=path, label = label) to image = Image.get_or_create(path=path) since i was having this error -

cursor.execute(sql, params or ())
peewee.OperationalError: near ",": syntax error

Really require help with this. Thanks a lot.

bfk1690 commented 5 years ago

use image = Image.get_or_create(path=path, label=label) and delete image.save()