From dd08df5f4f135de6d82b9a379224c24c637c8e91 Mon Sep 17 00:00:00 2001 From: cailean Date: Mon, 30 Sep 2024 14:29:17 +0100 Subject: [PATCH] fixed batch emotion --- src/ofApp.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 66212f3..b619592 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -70,7 +70,7 @@ void ofApp::update(){ Create a dummy initial input of batch_size = 5, as when initialising the model, it will attempt to create a space in memory for this array. If the batch_size does change it will completely slow down inference, due to how the cudnn_search_algo is set. - None of the other search alogithms bar EXHAUSTIVE will work.. no idead why. + None of the other search alogithms bar EXHAUSTIVE will work.. no idea why. */ for(int i = 0; i < emotionImageMaxBatchSize; i++){ tempImage.setFromPixels(emoteImage.getPixels()); @@ -137,19 +137,17 @@ void ofApp::inferEmotionalState(){ auto output_shap = output_tensor.GetTensorTypeAndShapeInfo().GetShape(); size_t batch_size = output_shap[0]; // Number of images in the batch size_t num_classes = output_shap[1]; // Number of emotion classes - std::cout << batch_size << " : " << num_classes << std::endl; - - // for(int i = 0; i < max_faces_to_process; ++i){ - // auto& face = detected_faces[i]; - // faceDetector.CropFaceToImage(img, face, emoteImage); - // tempImage.setFromPixels(emoteImage.getPixels()); - // auto emotion_output_tensor = emotion.Run(tempImage); - // float* emotional_data = emotion_output_tensor.front().GetTensorMutableData(); - // emotion.Softmax(emotional_data, 7); - // face.box.SetEmotionState(emotional_data); - // } - - std::cout << croppedFaces.size() << std::endl; + + float* emotional_data = output_tensor.GetTensorMutableData(); + + for (size_t i = 0; i < max_faces_to_process; i++){ + + float* emotion_values = emotional_data + i * num_classes; + + emotion.Softmax(emotion_values, num_classes); + + detected_faces[i].box.SetEmotionState(emotion_values); + } } //--------------------------------------------------------------