Xtra-Computing / thundersvm

ThunderSVM: A Fast SVM Library on GPUs and CPUs
Apache License 2.0
1.56k stars 217 forks source link

ThunderSVM Training failed but LibLinear succeed #214

Closed AtlantixJJ closed 4 years ago

AtlantixJJ commented 4 years ago

Hi, I tried to train a face segmentation using ThunderSVM but the result is very bad. I compare it to an implementation using LibLinear and found that the latter succeed.

The only differences in code are two segments below:

# build model
if USE_THUNDER:
    print("=> Use thundersvm")
    from thundersvm import OneClassSVM as SVM
else:
    print("=> Use liblinear (multicore)")
    import lib.liblinear.liblinearutil as svm
if USE_THUNDER:
    svm_model = SVM(kernel="linear")
    svm_model.fit(feats, labels_C)
    est_labels = svm_model.predict(feats)
else:
    svm_model = svm.train(labels_C, feats, "-n 32 -s 2 -B -1 -q")
    est_labels, acc, vals = svm.predict(labels_C, feats, svm_model)
    est_labels = np.array(est_labels)

The result in shown below:

Image:

thunder_svm_image_0_b4

ThunderSVM (odd images are labels, even images are predictions):

thunder_svm_train_0_c1_l4_b4

LibLinear (the same):

liblinear

LibLinear works out perfectly while ThunderSVM fails.

The feature shape is:

=> Feature shape: torch.Size([4, 256, 64, 64])
=> Label shape: torch.Size([4, 1, 64, 64])
=> Feature for SVM shape: (16384, 256)
=> Class 1 On: 4241 Off: 12143

I normalized the feature to have L2 norm 1.

Is there some issues in the implementation for OneClassSVM linear kernel or I miss something to run it correctly?

Upate: SVC seems ok. Maybe you can look into OneClassSVM.

zeyiwen commented 4 years ago

@AtlantixJJ Is your face segmentation problem a binary classification problem, regression problem or a one-class classification problem? If your problem is a binary classification problem, you shouldn't use OneClassSVM.

I believe the Liblinear you used is for binary classification.