Skip to content

Commit

Permalink
Added test for emotion detector
Browse files Browse the repository at this point in the history
  • Loading branch information
Anirudh58 committed Sep 13, 2022
1 parent 5ceeabf commit 70c59a9
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/udfs/test_emotion_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# coding=utf-8
# Copyright 2018-2022 EVA
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
from pathlib import Path
from test.util import EVA_TEST_DATA_DIR

import cv2
import pandas as pd

from eva.models.storage.batch import Batch


class EmotionDetector(unittest.TestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.base_path = Path(EVA_TEST_DATA_DIR) / "data" / "emotion_detector"

def _load_image(self, path):
assert path.exists(), f"File does not exist at the path {str(path)}"
img = cv2.imread(str(path))
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

def test_should_return_correct_emotion(self):
from eva.udfs.emotion_detector import EmotionDetector

happy_img = self.base_path / "happy.jpg"
sad_img = self.base_path / "sad.jpg"
angry_img = self.base_path / "angry.jpg"

frame_happy = {
"id": 1,
"data": self._load_image(happy_img),
}

frame_sad = {
"id": 2,
"data": self._load_image(sad_img),
}

frame_angry = {
"id": 3,
"data": self._load_image(angry_img),
}

frame_batch = Batch(pd.DataFrame([frame_happy, frame_sad, frame_angry]))
detector = EmotionDetector()
result = detector.classify(frame_batch.project(["data"]).frames)

self.assertEqual("happy", result.iloc[0]["labels"])
self.assertEqual("sad", result.iloc[1]["labels"])
self.assertEqual("angry", result.iloc[2]["labels"])

0 comments on commit 70c59a9

Please sign in to comment.