我试图将已保存为数组列表的图像要素表示通过kmeans进行聚类。
features_list = []
features = np.asarray(features_list)
features_flat = features.reshape((features.shape[0], -1))
k_means = cluster.KMeans(n_clusters=10, n_jobs=-1)
k_means.fit(features_flat)
有关features_flat的信息如下:
print(features_flat)
Out:[[ array([[[ 0.36470588, 0.32156863, 0.2627451 , 0.36862745],
[ 0.36470588, 0.32156863, 0.2627451 , 0.36862745],
[ 0.36470588, 0.32156863, 0.2627451 , 0.36862745],
...,
[ array([[[ 0.19607843, 0.19215686, 0.14117647, 0.30980392],
[ 0.19607843, 0.19215686, 0.14117647, 0.30980392],
[ 0.19607843, 0.19215686, 0.14117647, 0.30980392],
...,
]]
np.unique(list(map(len, features_flat)))
Out: array([1])
运行k_means.fit()
时出现以下错误ValueError: setting an array element with a sequence.
如何在创建正确类型的矩阵时保留数组中的数据?
答案 0 :(得分:0)
谢谢@lejlot
它适用于此转换的图像表示。
Standardized image size for each image + mapped to grayscale
我希望它可以使用下面的图像表示
,但这解决了这个特殊问题。