【问题标题】:python module utils :has no attribute 'centord_histogram'python模块实用程序:没有属性'centord_histogram'
【发布时间】:2019-04-27 13:09:47
【问题描述】:

我在导入 python 模块时遇到问题

from sklearn.cluster import KMeans


import argparse
import utils
import cv2
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt






image = image.reshape((image.shape[0] * image.shape[1], 3))

# cluster
clt = KMeans(n_clusters = 2)
clt.fit(image)


hist = utils.centord_histogram(clt)
bar = utils.plot_colors(hist, clt.cluster_centers_)



plt.figure()
plt.axis("off")
plt.imshow(bar)
plt.show()

添加了 import matplotlib as mpl mpl.use('TkAgg') 因为我是 Mac 用户。

当我运行代码时,

hist = utils.centord_histogram(clt)

我得到以下信息:

AttributeError: module 'utils' has no attribute 'centord_histogram'

发生错误。我必须看到直方图。对此有何建议?

【问题讨论】:

    标签: python matplotlib module


    【解决方案1】:

    我想你的意思是写utils.centroid_histogram 而不是utils. centord_histogram

    【讨论】:

      【解决方案2】:

      这不是来自utils 的模块,您可以通过安装像pip install utils 这样的工具来导入它。这是一个书面代码。

      在这里找到你的答案: https://github.com/tarikd/python-kmeans-dominant-colors/blob/master/utils.py

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-26
        • 2017-03-05
        • 1970-01-01
        • 1970-01-01
        • 2023-04-06
        • 2015-12-17
        • 1970-01-01
        • 2018-04-28
        相关资源
        最近更新 更多