Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

python - Im trying covert 2 images into ndarrays using openv and using it to train a regression model but I keep getting a Error

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...