簡體   English   中英

高斯混合模型 (GMM) 提供與訓練數據無關的結果

[英]Gaussian Mixture Model (GMM) delivers results that are unrelated to the training data

左起:入口點和出口點,GMM 有 2 個分量,GMM 有 3 個分量

正如您在圖像中看到的,聚類似乎與提供的數據完全無關。 我有 34 個數據點。 這可能是什么原因?

用不同的組件擬合 K GMM:

  def calculate_zones(self):

    mini_data = []
    for id, enter_x, enter_y, enter_time, exit_x, exit_y, exit_time in self.data:
        mini_data.append([enter_x, enter_y])
        mini_data.append([exit_x, exit_y])

    K = range(2, 4)

    for k in K:
        # Set the model and its parameters
        self.gms.append(
            GaussianMixture(n_components=k, n_init=20, covariance_type='spherical', init_params='kmeans').fit(
                mini_data))

根據 GMM 的結果屏蔽圖像:

  def display_zones(self):
    video = cv2.VideoCapture(self.video_path)
    if not video.isOpened():
        print("Cannot open stream")
        exit()
    _, frame = video.read()

    mask = []

    colors = random_color(11)

    for model in self.gms:
        curr_mask = np.zeros_like(frame)
        mask.append(curr_mask)
        row_index = 0
        for pixel_row in frame:
            column_index = 0
            for _ in pixel_row:
                prediction = model.predict_proba([[row_index, column_index]])

                best_proba = 0
                counter = 0
                for one_prediction in prediction[0]:
                    if one_prediction > prediction[0][best_proba]:
                        best_proba = counter
                    counter += 1

                curr_mask[row_index][column_index] = colors[best_proba]
                column_index += 1

            row_index += 1

首先,您應該為每個班級配備一個 GMM。 GMM 是一種無監督的概率算法,因此您不能為.fit()函數提供多個類並期望它天生區分類(除非您的目的是將區域映射在一起,否則這種方法很好)。

其次,您使用格式如下的數據訓練模型:

mini_data = []
for id, enter_x, enter_y, enter_time, exit_x, exit_y, exit_time in self.data:
    mini_data.append([enter_x, enter_y])
    mini_data.append([exit_x, exit_y])

但是然后使用以下方法獲得預測:

for _ in pixel_row:
     prediction = model.predict_proba([[row_index, column_index]])

函數的輸入不應該是[[column_index, row_index]]以匹配訓練數據的[x,y]格式嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM