I'm working on a class assignment which needs to implement nu-SVM and c-SVM to classify a image dataset(part of MINIST) using python and libsvm library (can't use sklearn), and I successfully implement c-SVM including training and predicting, but when it comes to nu-SVM, the training part runs successfully, but when I run the code of prediction "p_label, p_acc, p_val = svm_predict(test_t, test_x, model)" my compiler just breaks, shows "Canceled future for execute_request message before replies were done" and crashed, it seems that the kernel was crashed, but I'm don't know why svm_predict() function will get error when implementing nu-SVM, while it's totally fine when implementing nu-SVM. Here's my code down below:
import os
import numpy as np
from scipy.interpolate import Rbf
from PIL import Image
from libsvm.svmutil import *
root_train = 'picture/train'
root_test = 'picture/test'
def dataset(root, mode):
img_path=os.listdir(root)
if mode == 'train':
N = 5000
elif mode == 'test':
N = 2500
img = np.empty([N, 784])
for i in range(N):
img_name = img_path[i]
image_id_path = os.path.join(root,img_name)
img[i]=Image.open(image_id_path).convert("L").resize([784,1])
img[i]=(img[i]-np.amin(img[i]))/(np.amax(img[i])-np.amin(img[i]))
return img
train_t=np.zeros(5000,)
train_t[0:1000] = 0
train_t[1000:2000] = 1
train_t[2000:3000] = 2
train_t[3000:4000] = 3
train_t[4000:] = 4
test_t=np.zeros(2500)
test_t[0:500] = 0
test_t[500:1000] = 1
test_t[1000:1500] = 2
test_t[1500:2000] = 3
test_t[2000:] = 4
train_x = dataset(root_train, 'train')
test_x = dataset(root_test, 'test')
model = svm_train(train_t, train_x, '-s 1 -c 100 -t 2')
svm_save_model('modelnu_svm', model)
*#The error part*
p_label, p_acc, p_val = svm_predict(test_t, test_x, model)
At first I thought it might because I don't have enough memory space to do the computation, so I change the environment but it still break on the same line, so I thought maybe I use svm_predict() wrong, but I don't know which point I do it wrong, so if anyone knows the solution please save me.