def predict(features: numpy.ndarray) -> float: x, idx = svmutil.gen_svm_nodearray( features, isKernel=(model.param.kernel_type == svmutil.PRECOMPUTED) ) nr_classifier = 1 prob_estimates = (svmutil.c_double * nr_classifier)() return svmutil.libsvm.svm_predict_probability(model, x, prob_estimates)
def calculate_image_quality_score(brisque_features): model = svmutil.svm_load_model('utils/brisque/brisque_svm.txt') scaled_brisque_features = scale_features(brisque_features) x, idx = svmutil.gen_svm_nodearray( scaled_brisque_features, isKernel=(model.param.kernel_type == svmutil.PRECOMPUTED)) nr_classifier = 1 prob_estimates = (svmutil.c_double * nr_classifier)() return svmutil.libsvm.svm_predict_probability(model, x, prob_estimates)
def _calculate_score(self, scaled_feature): """Calculate score from scaled brisque feature. :param scaled_feature: Scaled brisque feature. :type scaled_feature: np.ndarray """ x, idx = gen_svm_nodearray( scaled_feature.tolist(), isKernel=(self._model.param.kernel_type == 'PRECOMPUTED')) nr_classifier = 1 prob_estimates = (c_double * nr_classifier)() return svmutil.libsvm.svm_predict_probability(self._model, x, prob_estimates)
def calculate_image_quality_score(brisque_features): ''' Using a pre-trained SVR model we calculate the quality assessment scores. ''' model = svmutil.svm_load_model(os.path.join("deeppixel", "iqa", "brisque_svm.txt")) scaled_brisque_features = scaled(brisque_features) x, idx = svmutil.gen_svm_nodearray( scaled_brisque_features, isKernel=(model.param.kernel_type == svmutil.PRECOMPUTED)) nr_classifier = 1 prob_estimates = (svmutil.c_double * nr_classifier)() return svmutil.libsvm.svm_predict_probability(model, x, prob_estimates)
def predict(data, path): if not os.path.exists(path): print 'Model path does not exist, do nothing.' return print "Loading features." integerizer = tools.integerization.CIntegerization.read(os.path.join(path, 'int')) model = svmutil.svm_load_model(os.path.join(path, "scr")) print "Decoding." for sent in posreader.readpossent(data): print sent for start in range(len(sent)): for end in range(start, len(sent)): label, feature = extractfeat.extractOneFeat(sent, (start, end, None), integerizer) assert label == -1 nodes, x = svmutil.gen_svm_nodearray(feature) label = svm.libsvm.svm_predict(model, nodes) probabilities = (ctypes.c_double*2)() label = svm.libsvm.svm_predict_probability(model, nodes, probabilities) print start, end, probabilities[0], probabilities[1]
def predict(data, path): if not os.path.exists(path): print 'Model path does not exist, do nothing.' return print "Loading features." integerizer = tools.integerization.CIntegerization.read(os.path.join(path, 'int')) model = svmutil.svm_load_model(os.path.join(path, "scr")) print "Working." for sent in io.getsent(data): labels = [] for index in range(len(sent)): f = feature.extractFeatures(sent, index, integerizer) nodes, x = svmutil.gen_svm_nodearray(f) probabilities = (ctypes.c_double*2)() label = svm.libsvm.svm_predict_probability(model, nodes, probabilities) x = 1 if probabilities[0] > cutoff: x = 0 labels.append(str(x)) print ' '.join(labels)
def predict(data, path): if not os.path.exists(path): print 'Model path does not exist, do nothing.' return print "Loading features." integerizer = tools.integerization.CIntegerization.read( os.path.join(path, 'int')) model = svmutil.svm_load_model(os.path.join(path, "scr")) print "Working." for sent in io.getsent(data): labels = [] for index in range(len(sent)): f = feature.extractFeatures(sent, index, integerizer) nodes, x = svmutil.gen_svm_nodearray(f) probabilities = (ctypes.c_double * 2)() label = svm.libsvm.svm_predict_probability(model, nodes, probabilities) x = 1 if probabilities[0] > cutoff: x = 0 labels.append(str(x)) print ' '.join(labels)