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

EmotionDetector error #323

Open
yuanych opened this issue Dec 21, 2023 · 1 comment
Open

EmotionDetector error #323

yuanych opened this issue Dec 21, 2023 · 1 comment

Comments

@yuanych
Copy link

yuanych commented Dec 21, 2023

Code:

class EmotionDetector(pr.Processor):
def init(self):
super(EmotionDetector, self).init()
self.detect = HaarCascadeFrontalFace(draw=False)
self.crop = pr.CropBoxes2D()
self.classify = MiniXceptionFER()
self.draw = pr.DrawBoxes2D(self.classify.class_names)

def call(self, image):
    boxes2d = self.detect(image)['boxes2D']
    cropped_images = self.crop(image, boxes2d)
    results = []
    for cropped_image, box2D in zip(cropped_images, boxes2d):
        result = self.classify(cropped_image)
        box2D.class_name = result['class_name']
        box2D.score = np.amax(result['scores'])
        info = {"name": box2D.class_name, "score": float(box2D.score), "x": int(box2D.coordinates[0]),
                "y": int(box2D.coordinates[1]), "w": int(box2D.width), "h": int(box2D.height)}
        results.append(info)
        # print(f"result: {result} box2D: {box2D}")
    return results

detect = EmotionDetector()
def emotion_classifier(image_bytes, width, height):
numpy_array = np.asarray(image_bytes)
json_detect = detect(numpy_array)

Sometimes it throws an error, and sometimes it is correct.

error1:
boxes2d = self.detect(image)['boxes2D']
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/abstract/processor.py", line 54, in call
return self.call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/pipelines/detection.py", line 454, in call
boxes2D = self.predict(image)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/abstract/processor.py", line 54, in call
return self.call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/processors/standard.py", line 247, in call
return predict(x, self.model, self.preprocess, self.postprocess)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/backend/standard.py", line 268, in predict
y = model(x)
^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/models/detection/haar_cascade.py", line 47, in call
boxes = self.model.detectMultiScale(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.8.1) /Users/xperience/GHA-OpenCV-Python/_work/opencv-python/opencv-python/opencv/modules/objdetect/src/cascadedetect.hpp:46: error: (-215:Assertion failed) 0 <= scaleIdx && scaleIdx < (int)scaleData->size() in function 'getScaleData'

error2:
json_detect = detect(numpy_array)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/abstract/processor.py", line 54, in call
return self.call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/yuanych/research/ZLMediaKit-8.0/ZLMediaKit/Python/emotion_classifier.py", line 18, in call
boxes2d = self.detect(image)['boxes2D']
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/abstract/processor.py", line 54, in call
return self.call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/pipelines/detection.py", line 454, in call
boxes2D = self.predict(image)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/abstract/processor.py", line 54, in call
return self.call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/processors/standard.py", line 247, in call
return predict(x, self.model, self.preprocess, self.postprocess)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/backend/standard.py", line 268, in predict
y = model(x)
^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/paz/models/detection/haar_cascade.py", line 47, in call
boxes = self.model.detectMultiScale(*args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: vector

@invisiblecao
Copy link

I have similar errors, but mainly regarding the outdated argument 'lr' in the model file. Did you have such error?

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