Spaces:
Sleeping
Sleeping
import pandas as pd | |
from feat import Detector | |
# 検出器の定義 | |
detector = Detector() | |
class EmotionAnalyzer: | |
def __init__(self, img_file_path_list): | |
self.img_file_path_list = img_file_path_list | |
def create_emotion_dataflame(self): | |
""" | |
イメージファイルの分析結果をデータフレーム化 | |
""" | |
emotions_deg_list = [] | |
result_detections_list = [] | |
for img_file_path in self.img_file_path_list: | |
result_emotions_mean, result_detections = self.analyze_emotion(img_file_path) | |
emotions_deg_list.append(result_emotions_mean) | |
result_detections_list.append(result_detections) | |
df_emotion_result = pd.DataFrame(emotions_deg_list, index=self.img_file_path_list) | |
df_emotion_result['detections'] = result_detections_list | |
return df_emotion_result | |
def analyze_emotion(img_file_path): | |
""" | |
イメージファイルから感情を分析 | |
""" | |
# 検出器の定義 | |
detector = Detector() | |
result = detector.detect_image(img_file_path) | |
result_emotions_mean = result.emotions.mean() | |
return result_emotions_mean, result | |