我正在 App Engine 上开发一个应用程序,并且正在使用来自 SciPy 的 kmeans2。
当集群运行时,我收到此错误:
Exceeded soft private memory limit with 159.852 MB after servicing 1 requests total
这是我正在做的事情,color_data
大约有 500 万个 x、y、z 点:
def _cluster(color_data, k):
""" Clusters colors and return top k
Arguments:
----------
color_data
TYPE: list
DESC: The pixel rgb values to cluster
k
TYPE: int
DESC: number of clusters to find in the colors
Returns:
--------
sorted_colors
TYPE: list
DESC: A list of rgb centroids for each color cluster
"""
# make rgbs into x,y,z points
x,y,z = [],[],[]
for color in color_data:
x.append(color[0])
y.append(color[1])
z.append(color[2])
# averaged_colors are points at center of color clusters
# labels are cluster numbers for each point
averaged_colors, labels = kmeans2(array(zip(x,y,z)), k, iter=10)
# get count of nodes per cluster
frequencies = {}
for i in range(k):
frequencies[i] = labels.tolist().count(i)
# sort labels on frequency
sorted_labels = sorted(frequencies.iteritems(), key=itemgetter(1))
# sort colors on label they belong to
sorted_colors = []
for l in sorted_labels:
sorted_colors.append(tuple(averaged_colors[l[0]].tolist()))
return sorted_colors
如何在 128MB 以下的内存中做到这一点?
编辑:在我的本地机器上,运行我的应用程序显示我的活动监视器中使用了约 500 MB 的内存