-
Notifications
You must be signed in to change notification settings - Fork 19
/
demo_pred_MOS_pretrained_VIDEVAL.py
69 lines (56 loc) · 2.04 KB
/
demo_pred_MOS_pretrained_VIDEVAL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""
This script predicts a quality score in [1,5] given a VIDEVAL feature
vector by a pretrained VIDEVAL model
Input:
- feature matrix:
eg, features/TEST_VIDEOS_VIDEVAL_feats.mat
Output:
- predicted scores:
eg, results/TEST_VIDEOS_VIDEVAL_pred.csv
"""
# Load libraries
from sklearn import model_selection
import os
import warnings
import time
import scipy.io
from sklearn.svm import SVR
import numpy as np
from sklearn.svm import SVC
from sklearn.preprocessing import MinMaxScaler
from sklearn.externals import joblib
# ignore all warnings
warnings.filterwarnings("ignore")
# ===========================================================================
# Here starts the main part of the script
#
'''======================== parameters ================================'''
model_name = 'SVR'
data_name = 'TEST_VIDEOS'
algo_name = 'VIDEVAL'
mat_file = os.path.join('features', data_name+'_'+algo_name+'_feats.mat')
model_file = os.path.join('model', algo_name+'_trained_svr.pkl')
scaler_file = os.path.join('model', algo_name+'_trained_scaler.pkl')
pars_file = os.path.join('model', algo_name+'_logistic_pars.mat')
result_file = os.path.join('results', data_name+'_'+algo_name+'_pred.csv')
print("Predict quality scores using pretrained {} with {} on dataset {} ...".format(
algo_name, model_name, data_name))
'''======================== read files =============================== '''
X_mat = scipy.io.loadmat(mat_file)
X = np.asarray(X_mat['feats_mat'], dtype=np.float)
X[np.isnan(X)] = 0
X[np.isinf(X)] = 0
model = joblib.load(model_file)
scaler = joblib.load(scaler_file)
popt = np.asarray(scipy.io.loadmat(pars_file)['popt'][0], dtype=np.float)
X = scaler.transform(X)
y_pred = model.predict(X)
def logistic_func(X, bayta1, bayta2, bayta3, bayta4):
logisticPart = 1 + np.exp(np.negative(np.divide(X - bayta3, np.abs(bayta4))))
yhat = bayta2 + np.divide(bayta1 - bayta2, logisticPart)
return yhat
y = logistic_func(y_pred, *popt)
print('Predicted MOS in [1,5]:')
print(y)
np.savetxt(result_file, y, delimiter=",")