Issue
I'm making a custom training model for classification I tested the trained model on a PC with 2 CPU and 32 RAM with 4 G GPU but it's slower than Laptop 8 G Ram without GPU as shown on the screenshots My PC Takes almost 1 hour, my laptop takes 10 minutes so why is that?
This is the screen of my Laptop with windows 10 https://ibb.co/1zQn9Vm
This is the screen of my PC with windows 11 https://ibb.co/j8WTTL0
That is my code:
target = []
images =[]
flat_data =[]
DATADIR = r"Images"
CATEGORIES = ['cat1', 'cat2', 'cat3', 'cat4']
for cat in CATEGORIES:
class_num = CATEGORIES.index(cat)
path = os.path.join(DATADIR, cat)
for img in os.listdir(path):
img2 = Image.open(os.path.join(path, img))
compression_image = img2.info['compression']
if(compression_image == 'group4'):
img2.save(os.path.join(path, img), compression='tiff_lzw')
img_array = imread(os.path.join(path, img))
img_resized = resize(img_array, (200 , 200))
flat_data.append(img_resized.flatten())
images.append(img_resized)
target.append(class_num)
flat_data = np.array(flat_data)
target = np.array(target)
images = np.array(images)
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test= train_test_split(flat_data,
target, test_size=0.3, random_state= 109)
from sklearn.model_selection import GridSearchCV
from sklearn import svm
param_grid = [
{'C': [1, 10, 100, 1000], 'kernel': ['linear']},
{'C': [1, 10, 100, 1000], 'gamma': [0.001, 0.0001], 'kernel':
['rbf']}
]
svc = svm.SVC(probability= True)
clf = GridSearchCV(svc, param_grid)
clf.fit(x_train, y_train)
Solution
After I added this parameter It works well.
GridSearchCV try setting n_jobs=-1
Answered By - Emad Younan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.