gpt4 book ai didi

Python-图像识别分类器

转载 作者:行者123 更新时间:2023-11-30 09:00:25 24 4
gpt4 key购买 nike

我想评估我的屏幕上是否发生了某个事件,每次发生时,都会在屏幕区域中显示一个具有非常相似结构的特定框/图像。

我从该屏幕区域收集了一堆 84x94 .png RGB 图像,我想构建一个分类器来告诉我事件是否正在发生或不是。

因此我的想法是创建一个包含 2 列的 pd.DataFrame (df),df['np_array'] 包含每张图片作为 np.arraydf['is_category'] 包含 bool 值,告诉图像是否表明事件正在发生。

结构如下所示(!=大小):

我已将图像大小调整为 10x10 以进行训练并转换为灰度

df = pd.DataFrame(
{'np_array': [np.random.random((10, 10,2)) for x in range(0,10)],
'is_category': [bool(random.getrandbits(1)) for x in range(0,10)]
})

我的问题是我无法通过执行 clf.fit(df['np_array'],df['is_category']) 来适应 scikit learn 分类器

我以前从未尝试过图像识别,首先感谢您的帮助!

最佳答案

如果是 10x10 灰度图像,您可以将其展平:

import numpy as np
from sklearn import ensemble

# generate random 2d arrays
image_data = np.random.rand(10,10, 100)

# generate random labels
labels = np.random.randint(0,2, 100)

X = image_data.reshape(100, -1)

# then use any scikit-learn classification model
clf = ensemble.RandomForestClassifier()
clf.fit(X, y)

顺便说一句,对于图像来说,性能最好的算法是卷积神经网络。

关于Python-图像识别分类器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42249136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com