here is the code I have Written:(NOTE: image1.jpg and image2.jpg have the same dimensions but are diffrent photos)
import cv2,numpy as np
from sklearn import svm
im = cv2.imread("image1.jpg")
im1d = np.reshape(im,(1609200))#reshape to 1d from (596,900,3) because in svm.SVR(X,y), y must =1d
cdata = cv2.imread('image2.jpg')
rdata = np.reshape(cdata,(596,2700))#reshape to 2d from (596,900,3)because in svm.SVR(X,y),X must =2d
regr = svm.SVR()
regr.fit(rdata, im1d)
i =regr.predict(rdata)#rdata is a part of training data just wanted to see if the code works
b = np.reshape(i,(596,900,3))#reshape to 3d so it can be viewed as a photo
cv2.imshow(b)
The error I get is:
Traceback (most recent call last):
File "D: FolderPythonmodule propertiesimg.py", line 10, in <module>
regr.fit(rdata, im1d)
File "C:UsersAdmin1AppDataLocalProgramsPythonPython39libsite-packagessklearnsvm\_base.py", line 169, in fit
X, y = self._validate_data(X, y, dtype=np.float64,
File "C:UsersAdmin1AppDataLocalProgramsPythonPython39libsite-packagessklearnase.py", line 433, in _validate_data
X, y = check_X_y(X, y, **check_params)
File "C:UsersAdmin1AppDataLocalProgramsPythonPython39libsite-packagessklearnutilsvalidation.py", line 63, in inner_f
return f(*args, **kwargs)
File "C:UsersAdmin1AppDataLocalProgramsPythonPython39libsite-packagessklearnutilsvalidation.py", line 831, in check_X_y
check_consistent_length(X, y)
File "C:UsersAdmin1AppDataLocalProgramsPythonPython39libsite-packagessklearnutilsvalidation.py", line 262, in check_consistent_length
raise ValueError("Found input variables with inconsistent numbers of"
ValueError: Found input variables with inconsistent numbers of samples: [596, 1609200]
I think this means rdata and im1d dont have the same number of samples but I dont know how to solve it
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…