0
$\begingroup$

I have a model that i need to train multiple times using epochs, i tried adding this code clf_svm.fit(train_features, train_labels, epochs=10, batch_size=64) and it didn't work. how to add epoches in skleran linear svc? training that model several times and save the model here is the code am working with

# empty list to hold feature vectors and train labels
train_features = []
train_labels   = []
# loop over the training dataset
print ("[STATUS] Started extracting haralick textures..")

for train_name in train_names:
    cur_path = train_path + "/" + train_name
    cur_label = train_name
    i = 1
    for file in glob.glob(cur_path + "/*.jpg"):
        
        print ("Processing Image - {} in {}".format(i, cur_label))
        
        # read the training image
        image = cv2.imread(file)
        #resize = ResizeWithAspectRatio(image, width=1250, height=1000) # Resize by width OR
        # convert the image to grayscale
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        # extract haralick texture from the image
        features = extract_features(gray)

        # append the feature vector and label
        train_features.append(features)
        train_labels.append(cur_label)
        
        # otherwise create the model, train the model and save the model
if os.path.exists("D:/ai training/aphids/joblib_model.sav"):
    print("Loading Trained Model")
    clf_svm = joblib.load("D:/ai training/aphids/joblib_model.sav")
else:
        # have a look at the size of our feature vector and labels
        print ("Training features: {}".format(np.array(train_features).shape))
        print ("Training labels: {}".format(np.array(train_labels).shape))

        # create the classifier
        print ("[STATUS] Creating the classifier..")
        clf_svm = LinearSVC(random_state=9, dual=False, max_iter=1000)

        # fit the training data and labels
        print ("[STATUS] Fitting data/label to model..")
        clf_svm.fit(train_features, train_labels)

        #savemodel
        joblib_file = 'D:/ai training/aphids/joblib_model.sav'
        joblib.dump(clf_svm, joblib_file)
        
$\endgroup$
1
  • $\begingroup$ What you mean by "didn't work? What are you exactly looking for with "epochs" $\endgroup$
    – 10xAI
    Apr 12, 2021 at 7:00

2 Answers 2

1
$\begingroup$

Support vector machine model in sklearn support adding max iterations parameter which you can change to a higher value. But they don't have epochs parameters nor do they support batch sizes.

To go into more depth, support vectors use an exact convex optimization algorithm, not stochastic gradient descent (like Neural nets). They work on the entire dataset at the same time. The algorithm will run for max iterations or till minimum value is achieved and report one single accuracy number.

From the question it is not clear why you want to train multiple times using epochs. Comparing with neural networks, the equivalent here will be to just set high max iterations parameter and training once.

$\endgroup$
0
$\begingroup$

SVM does not learn iteratively unlike Neural Networks that's why they cant possess EPOCH parameters. see: https://scikit-learn.org/stable/modules/svm.html

$\endgroup$
5
  • $\begingroup$ so is it possible to convert to keras models? I'm new to to machine learning $\endgroup$ Apr 12, 2021 at 8:20
  • $\begingroup$ it's possible to add in deep learning models which are being built using Keras, Theano etc $\endgroup$ Apr 12, 2021 at 8:21
  • $\begingroup$ SVM can not be built using Keras , I mean Keras has no function to built SVM . $\endgroup$ Apr 12, 2021 at 8:22
  • $\begingroup$ what am doing actually is to detect healthy leaf and infected leaf using haralic texture , is there is anyway to convert this to kares network ? or do i need to change ? or sklearn is enough for deep learning ? I'm confused actually $\endgroup$ Apr 12, 2021 at 8:34
  • $\begingroup$ you can either use Keras for deep learning or sklearn for machine learning generally, as you are a beginner I will suggest you use one for each. $\endgroup$ Jun 7, 2021 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.