add probs to us and update evaluate
Esse commit está contido em:
BIN
Arquivo binário não exibido.
+1
-1
@@ -10,7 +10,7 @@
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "aff-song/ResultsViewController.swift"
|
||||
timestampString = "536182084.662789"
|
||||
timestampString = "536673602.172784"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "6"
|
||||
|
||||
@@ -21,7 +21,7 @@ class ResultsViewController: AffUIViewController, UITableViewDataSource, UITable
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
ImageView.image = faceImage
|
||||
let (valence, arousal, emotion) = getAffect(image: faceImage)
|
||||
let (valence, arousal, emotion, _) = getAffect(image: faceImage)
|
||||
getSongs(valence: valence, arousal: arousal, emotion: emotion, callback: {tracks in
|
||||
self.tracks = tracks
|
||||
DispatchQueue.main.async {
|
||||
@@ -110,7 +110,7 @@ class ResultsViewController: AffUIViewController, UITableViewDataSource, UITable
|
||||
}
|
||||
|
||||
|
||||
func getAffect(image: UIImage?) -> (Double, Double, Int) {
|
||||
func getAffect(image: UIImage?) -> (Double, Double, Int, [String:Double]) {
|
||||
// 0: Neutral, 1: Happiness, 2: Sadness, 3: Surprise, 4: Fear, 5: Disgust, 6: Anger, 7: Contempt, 8: None, 9: Uncertain, 10: No-Face
|
||||
let pixelBuffer = image?.pixelBuffer(width: 128, height: 128)
|
||||
let classifier = MobAffNetC()
|
||||
@@ -122,6 +122,7 @@ class ResultsViewController: AffUIViewController, UITableViewDataSource, UITable
|
||||
var valence = predictedValArr.valence_arousal[0].doubleValue
|
||||
var arousal = predictedValArr.valence_arousal[1].doubleValue
|
||||
let emotion = Int(predictedEmotion.emotion)!
|
||||
let emotion_p = predictedEmotion.emotion_p
|
||||
var emotionText : String?
|
||||
switch emotion {
|
||||
case 0:
|
||||
@@ -156,7 +157,7 @@ class ResultsViewController: AffUIViewController, UITableViewDataSource, UITable
|
||||
}
|
||||
valence = max(-1, min(1, valence))
|
||||
arousal = max(-1, min(1, arousal))
|
||||
return (valence, arousal, emotion)
|
||||
return (valence, arousal, emotion, emotion_p)
|
||||
}
|
||||
|
||||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
||||
|
||||
@@ -40,12 +40,15 @@ class USResultsViewController: ResultsViewController, UINavigationControllerDele
|
||||
}
|
||||
}
|
||||
|
||||
override func getAffect(image: UIImage?) -> (Double, Double, Int) {
|
||||
let (valence, arousal, emotion) : (Double, Double, Int) = super.getAffect(image: image)
|
||||
override func getAffect(image: UIImage?) -> (Double, Double, Int, [String:Double]) {
|
||||
let (valence, arousal, emotion, emotion_p) = super.getAffect(image: image)
|
||||
data!.append("\(valence)")
|
||||
data!.append("\(arousal)")
|
||||
data!.append("\(emotion)")
|
||||
return (valence, arousal, emotion)
|
||||
for i in 0 ... 7 {
|
||||
data!.append("\(emotion_p["\(i)"] ?? 0)")
|
||||
}
|
||||
return (valence, arousal, emotion, emotion_p)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class USStartViewController : AffUIViewController, MFMailComposeViewControllerDe
|
||||
let filePath = url.path
|
||||
if !FileManager.default.fileExists(atPath: filePath) {
|
||||
do {
|
||||
try "id, us_emotion, emotion_label, predicted_valence, predicted_arousal, predicted_emotion_label, rating, annotated_valence, annotated_arousal\n".write(toFile: filePath, atomically: false, encoding: .utf8)
|
||||
try "id, us_emotion, emotion_label, predicted_valence, predicted_arousal, predicted_emotion_label, em0prob, em1prob, em2prob, em3prob, em4prob, em5prob, em6prob, em7prob, rating, annotated_valence, annotated_arousal\n".write(toFile: filePath, atomically: false, encoding: .utf8)
|
||||
}
|
||||
catch {
|
||||
print("ERROR WRITING FILE")
|
||||
@@ -58,7 +58,7 @@ class USStartViewController : AffUIViewController, MFMailComposeViewControllerDe
|
||||
let alert = UIAlertController(title: "Delete Data", message: "Are you sure you would like to delete all user study data?", preferredStyle: UIAlertControllerStyle.alert)
|
||||
alert.addAction(UIAlertAction(title: "Delete", style: UIAlertActionStyle.destructive, handler: { action in
|
||||
do {
|
||||
try FileManager.default.moveItem(atPath: filePath, toPath: filePath+".bak")
|
||||
try FileManager.default.removeItem(atPath: filePath)
|
||||
self.makeDataFile()
|
||||
}
|
||||
catch {
|
||||
|
||||
+47
-50
@@ -2,6 +2,7 @@
|
||||
|
||||
import csv
|
||||
import os
|
||||
import sys
|
||||
from math import sqrt
|
||||
|
||||
import numpy as np
|
||||
@@ -152,52 +153,47 @@ def eval(c_path=None, r_path=None):
|
||||
print('CCC'.ljust(20), str(CCC(valence_t, valence_p)).ljust(20), CCC(arousal_t, arousal_p))
|
||||
|
||||
|
||||
def eval_from_files(path):
|
||||
def eval_from_file(path):
|
||||
true_l = []
|
||||
pred_l = []
|
||||
pred_r = []
|
||||
with open(path + '/Emotion.csv', 'r') as csvfile:
|
||||
valence_t = []
|
||||
valence_p = []
|
||||
arousal_t = []
|
||||
arousal_p = []
|
||||
|
||||
with open(path, 'r') as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=',')
|
||||
for row in reader:
|
||||
if row[0] == '':
|
||||
if row[0] == '' or row[0] == 'id':
|
||||
continue
|
||||
true_l.append(int(row[0]))
|
||||
pred_l.append(int(row[1]))
|
||||
true_l.append(int(row[2]))
|
||||
pred_l.append(int(row[5]))
|
||||
probs = []
|
||||
for i in range(2, len(row)):
|
||||
for i in range(6, 13):
|
||||
probs.append(float(row[i]))
|
||||
pred_r.append(probs)
|
||||
|
||||
if row[15] == ' 0.00.0' or row[15] == '':
|
||||
valence_t.append(0)
|
||||
else:
|
||||
valence_t.append(float(row[15]))
|
||||
valence_p.append(float(row[3]))
|
||||
|
||||
if len(row) < 17 or (row[16] == ' 0.00.0' or row[16] == ''):
|
||||
arousal_t.append(0)
|
||||
else:
|
||||
arousal_t.append(float(row[16]))
|
||||
arousal_p.append(float(row[4]))
|
||||
true_r = to_categorical(true_l, num_classes=8)
|
||||
|
||||
print('ACC'.ljust(20), ACC(true_l, pred_l))
|
||||
print('F1'.ljust(20), F1(true_l, pred_l))
|
||||
print('KAPPA'.ljust(20), KAPPA(true_l, pred_l))
|
||||
print('ALPHA'.ljust(20), ALPHA(true_l, pred_l))
|
||||
print('AUCPR'.ljust(20), AUCPR(true_r, pred_r))
|
||||
print('AUC'.ljust(20), AUC(true_r, pred_r))
|
||||
valence_t = []
|
||||
valence_p = []
|
||||
with open(path + '/Valence.csv', 'r') as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=',')
|
||||
for row in reader:
|
||||
if row[0] == '':
|
||||
continue
|
||||
if row[0] == '0.00.0':
|
||||
valence_t.append(0)
|
||||
else:
|
||||
valence_t.append(float(row[0]))
|
||||
valence_p.append(float(row[1]))
|
||||
arousal_t = []
|
||||
arousal_p = []
|
||||
with open(path + '/Arousal.csv', 'r') as csvfile:
|
||||
reader = csv.reader(csvfile, delimiter=',')
|
||||
for row in reader:
|
||||
if row[0] == '':
|
||||
continue
|
||||
if row[0] == '0.00.0':
|
||||
arousal_t.append(0)
|
||||
else:
|
||||
arousal_t.append(float(row[0]))
|
||||
arousal_p.append(float(row[1]))
|
||||
print('')
|
||||
print(''.ljust(20), 'VALENCE'.ljust(20), 'AROUSAL')
|
||||
print('RMSE'.ljust(20), str(RMSE(valence_t, valence_p)).ljust(20), RMSE(arousal_t, arousal_p))
|
||||
print('CORR'.ljust(20), str(CORR(valence_t, valence_p)).ljust(20), CORR(arousal_t, arousal_p))
|
||||
@@ -205,23 +201,24 @@ def eval_from_files(path):
|
||||
print('CCC'.ljust(20), str(CCC(valence_t, valence_p)).ljust(20), CCC(arousal_t, arousal_p))
|
||||
|
||||
|
||||
eval_from_files('/Users/charlie/Desktop/us_results')
|
||||
# if __name__ == '__main__':
|
||||
# if len(sys.argv) == 3:
|
||||
# if sys.argv[1] == '-c':
|
||||
# eval(c_path=sys.argv[2])
|
||||
# elif sys.argv[1] == '-r':
|
||||
# eval(r_path=sys.argv[2])
|
||||
# else:
|
||||
# raise Exception()
|
||||
# elif len(sys.argv) == 5:
|
||||
# c_path = None
|
||||
# r_path = None
|
||||
# if sys.argv[1] == '-c':
|
||||
# eval(c_path=sys.argv[2], r_path=sys.argv[4])
|
||||
# elif sys.argv[1] == '-r':
|
||||
# eval(r_path=sys.argv[2], c_path=sys.argv[4])
|
||||
# else:
|
||||
# raise Exception()
|
||||
# else:
|
||||
# raise Exception()
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 3:
|
||||
if sys.argv[1] == '-c':
|
||||
eval(c_path=sys.argv[2])
|
||||
elif sys.argv[1] == '-r':
|
||||
eval(r_path=sys.argv[2])
|
||||
elif sys.argv[1] == '-f':
|
||||
eval_from_file(sys.argv[2])
|
||||
else:
|
||||
raise Exception()
|
||||
elif len(sys.argv) == 5:
|
||||
c_path = None
|
||||
r_path = None
|
||||
if sys.argv[1] == '-c':
|
||||
eval(c_path=sys.argv[2], r_path=sys.argv[4])
|
||||
elif sys.argv[1] == '-r':
|
||||
eval(r_path=sys.argv[2], c_path=sys.argv[4])
|
||||
else:
|
||||
raise Exception()
|
||||
else:
|
||||
raise Exception()
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário