gpt4 book ai didi

python - predict_classes() 的函数式 API Keras 替代解决方案

转载 作者:太空宇宙 更新时间:2023-11-04 00:38:49 25 4
gpt4 key购买 nike

请引用 here 我之前的问题以获得背景信息。根据 answer 建议的 Nassim Ben 。我使用函数式 API 训练了双路径架构模型。现在我觉得卡住了,因为我需要预测每个像素的类别。这是相同的代码:

    imgs = io.imread(test_img).astype('float').reshape(5,240,240)
plist = []

# create patches from an entire slice
for img in imgs[:-1]:
if np.max(img) != 0:
img /= np.max(img)
p = extract_patches_2d(img, (33,33))
plist.append(p)
patches = np.array(zip(np.array(plist[0]), np.array(plist[1]), np.array(plist[2]), np.array(plist[3])))

# predict classes of each pixel based on model
full_pred = self.model_comp.predict_classes(patches)
fp1 = full_pred.reshape(208,208)

但是根据 github-link predict_classes() 是不可用的。所以我的问题是我可以尝试其他替代方法吗?

最佳答案

Nassim 的回答很好,但我想与您分享我在类似任务中的经验:

  1. 切勿使用 predict_proba Keras 作为版本。 Here你可以找到原因。
  2. 用于将预测转化为类的大多数方法都没有考虑您的数据统计信息。在图像分割的情况下——通常检测对象比检测背景更重要。出于这个原因,我建议您使用从 precision-recall 获得的阈值。每个类的曲线。在这种情况下 - 您需要设置一个阈值,precision == recall(或者尽可能接近)。获得阈值后 - 您需要为类别预测编写自定义函数。

关于python - predict_classes() 的函数式 API Keras 替代解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42804939/

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