AttributeError: 'KMeans' object has no attribute 'labels_' with pytorch

first of all I thank , I tried to train model with pytorch but I got the following error: AttributeError: ‘KMeans’ object has no attribute ‘labels_’.I am trying to model a extract features point cloud using deep learning in pytorch. I get the following error . Could anyone help on this? ************** *************** Thanks!

def forward(self, feature_matrix_batch):
        # feature_matrix_batch size = (N,I,D) where N=batch number, I=members, D=member dimensionality
        N, I, D = feature_matrix_batch.size()
        clusters = []
        for i, feature_matrix in enumerate(feature_matrix_batch):
            kmeans = KMeans(n_clusters=self.k, init=self.kmeansInit, n_init=self.n_init)
            labels = np.apply_along_axis(lambda x: x + (i*self.k), axis=0, arr=kmeans.labels_)
            clusters.extend(labels)
        clusters = np.asarray(clusters)
        list1 = []
        list2 = []
        for i in range(self.k*N):
            indices = np.argwhere(clusters == i).flatten().tolist()
            if len(indices) != 1:
                edges = [e for e in netx.complete_graph(indices).edges]
                inverse_edges = list(map(lambda x: (x[1], x[0]), edges))
                edges.extend(inverse_edges)
                unzip = list(zip(*edges))
                list1.extend(unzip[0])
                list2.extend(unzip[1])
            else:
                list1.append(indices[0])
                list2.append(indices[0])

        edge_index = torch.tensor([list1, list2], dtype=torch.long, device=getDevice(feature_matrix_batch))
        edge_index = sort_edge_index(add_self_loops(edge_index)[0])[0]
        conv_feature_matrix_batch = self.conv(feature_matrix_batch.view(-1, D), edge_index).view(N, I, -1)
        # conv_feature_matrix_batch size = (N,I,L) where N=batch number, I=members, L=C+P
        return feature_matrix_batch, conv_feature_matrix_batch, torch.tensor(clusters, dtype=torch.long, device=getDevice(feature_matrix_batch))
labels = np.apply_along_axis(lambda x: x + (i*self.k), axis=0, arr=kmeans.labels_)
AttributeError: 'KMeans' object has no attribute 'labels_'

Thanks for your help

Welcome to the community.
I am just guessing, but you probably have to kmeans.fit() first?