简体   繁体   中英

How to fit image (multidimensional array) data into a random forest classifier in python?

I would like to build an image classifier using sklearn.ensemble

I have a list of image X_train where

X_train[0].shape
Out[58]: (353, 1054, 3)

and a list of scalar labels y_train.

Each image X_train[i] is of different shape. When I try to fit these data into the classifier, I get the following error

clf=RandomForestClassifier(n_estimators=100)

clf.fit(X_train,y_train)

ValueError: setting an array element with a sequence

How can I solve this problem?

The most basic solution would be to flatten the image into a single row with an element for each pixel. Do it for the size of the largest image and pad for the others.

This is a bad solution though and will probably not work well.

Image classification requires more sophisticated approaches beyond the scope of this question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM