Пример #1
0
def kMean(clusterNum):
    g = Graph(r"E:\ds2018")
    vocaDir = r"temp/vocabulary/"
    if not os.path.exists(vocaDir):
        os.makedirs(vocaDir)
    sift = SIFT()
    centers = []
    for i in range(g.getTypeNum()):
        print("[kmeans]:" + str(i))
        imgPaths = g.getTrainSet(i)
        features = np.float32([]).reshape((0, 128))
        for imgPath, type in imgPaths:
            imgMat = g.getGreyGraph(imgPath)
            if imgMat is None:
                print("[kmean]:" + imgPath + " is None")
                continue
            feature = sift.getFeature(imgMat)
            features = np.append(features, feature, axis=0)

        kmeans = KMeans(n_clusters=clusterNum).fit(features)
        filename = os.path.join(vocaDir, str(i) + ".npy")
        np.save(filename, kmeans.cluster_centers_)

        centers.append(kmeans.cluster_centers_)

    return centers
Пример #2
0
def loadVoca():
    g = Graph(r"E:\dataset")
    vocaDir = r"temp/vocabulary/"
    centers = []
    for i in range(g.getTypeNum()):
        filePath = os.path.join(vocaDir, str(i) + '.npy')
        _, center = np.load(filePath)
        centers.append(centers)

    return centers