Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
iamsashank09 opened this issue Jan 3, 2018 · 1 comment

Comments

@iamsashank09
Copy link

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
Copy link

bfk1690 commented Dec 12, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants