3

我目前正在研究使用贝叶斯网络对图像进行图像分类的问题。我试过使用pomegranate,pgmpybnlearn. 我的数据集包含超过 200,000 张图像,我在这些图像上执行了一些特征提取算法并获得了大小为 1026 的特征向量。

pgmpy

from pgmpy.models import BayesianModel
from pgmpy.estimators import HillClimbSearch, BicScore, K2Score
est = HillClimbSearch(feature_df, scoring_method=BicScore(feature_df[:20]))
best_model = est.estimate()
edges = best_model.edges()
model = BayesianModel(edges)

石榴

from pomegranate import *
model = BayesianNetwork.from_samples(feature_df[:20], algorithm='exact')

学习

library(bnlearn)
df <- read.csv('conv_encoded_images.csv')
df$Age = as.numeric(df$Age)
res <- hc(df)
model <- bn.fit(res,data = df)

用 R编写的程序在bnlearn几分钟内完成运行,而pgmpy运行数小时,石榴在几分钟后冻结了我的系统。您可以从我的代码中看到,我提供了前 20 行,用于在这两个程序中进行训练,同时pgmpy获取整个数据帧。由于我在 python 中进行所有图像预处理和特征提取,因此我很难在 R 和 python 之间切换进行训练。pomegranatebnlearn

我的数据包含从 0 到 1 的连续值。我还尝试将数据离散化为 0 和 1,但这并没有解决问题。

有什么方法可以加快这些 python 包的训练速度,还是我的代码做错了什么?

感谢您提前提供任何帮助。

编辑:

https://drive.google.com/file/d/1HbAqDQ6Uv1417zPFMgWBInC7-gz233j2/view?usp=sharing

这是具有 300 列和约 40000 行的数据集。如果您想尝试重现输出。

4

0 回答 0