Does scikit-learn provides GPU acceleration? Can I implement SVM using TensorFlow?

Viewed 31

I already installed the prerequisite to use Tensorflow running on my GPU. I already tested it by executing this block of codes:

import tensorflow as tf 

if tf.test.gpu_device_name(): 
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
   print("Please install GPU version of TF")

The block of code displayed an output of:

Default GPU Device: /device:GPU:0

However, when I started training my dataset using Multiclass SVM, I don't see my GPU Usage increasing on the task manager, but I see Python's CPU Usage is increasing while I train my model.

I don't know if I need to use the tensorflow or keras library while training or it should be using my GPU already.

Here's the code that I am executing for training:

import pandas as pd
from sklearn import svm
from sklearn.model_selection import GridSearchCV
import os
import matplotlib.pyplot as plt
from skimage.transform import resize
from skimage.io import imread
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report,accuracy_score,confusion_matrix
import pickle
Categories = ['Anger', 'AngrilyDisgusted', 'AngrilySurprised', 'Disgust', 
        'DisgustedlySurprised', 'Fear', 'FearfullyAngry', 'FearfullySurprised',
          'HappilyDisgusted', 'HappilySurprised', 'Happiness', 'Neutral',
          'SadlyAngry', 'SadlyDisgusted', 'SadlyFearful', 'SadlySurprised',
          'Sadness', 'Surprise']
flat_data_arr=[] #input array
target_arr=[] #output array
datadir='Batch4_Training_150/' 
#path which contains all the categories of images
for i in Categories:
    
    print(f'loading... category : {i}')
    path=os.path.join(datadir,i)
    for img in os.listdir(path):
        img_array=imread(os.path.join(path,img))
        img_resized=resize(img_array,(150,150,3))
        flat_data_arr.append(img_resized.flatten())
        target_arr.append(Categories.index(i))
    print(f'loaded category:{i} successfully')
flat_data=np.array(flat_data_arr)
target=np.array(target_arr)
df=pd.DataFrame(flat_data) #dataframe
df['Target']=target
x=df.iloc[:,:-1] #input data 
y=df.iloc[:,-1] #output data

x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.20,random_state=77,stratify=y)
print('Splitted Successfully')

param_grid={'C':[1,10],'gamma':[0.1,1],'kernel':['rbf','poly','linear']}
svc=svm.SVC(probability=True)
print("The training of the model is started, please wait for while as it may take few minutes to complete")
model=GridSearchCV(svc,param_grid)
model.fit(x_train,y_train)
print('The Model is trained well with the given images')
model.best_params_

I am also concerned on why Python's CPU Usage decreased to 10%-20% during the training. Earlier the usage was 60%-70%, but now it is just 10%-20%. I don't know if it is still on-going or not, because I don't see any progress bar about it. The asterisk symbol is still just there.

1 Answers

Under task manager where it says gpu 0 change it to cuda and it should display cuda part of your gpu

Related