I want to cluster the images using K Means or other algorithm(suggestion required).
The problem is like this- I want to cluster images into 3 clusters (nature, sunset, water). I loaded all the images using os.listdir() and then converted all of the images into arrays (RGB) and then created a data frame which contains three columns - ID, Image_array, Label.
Now, when I use K Means clustering, providing n_clusters = 3, it shows this error:
from sklearn.cluster import KMeans kmeans = KMeans(n_clusters = 3).fit(img_array) ERROR = Found array with dim 4. Estimator expected <= 2.
Now, I need your help in this clustering problem. The data frame that I created looks like this
img_array = []
path = "C://Users/shivam/Desktop/freelancer/p22/data/green_nature/"
for f in os.listdir('.'):
if f.endswith('.jpg'):
img = Image.open(f)
data = np.asarray(img, dtype='uint8')
img_array.append(data)
df = pd.DataFrame({'image_arrays':img_array})
df['id'] = range(1, len(df) + 1)