Predict_classes() 的函数式 API Keras 替代解决方案

2023-12-14

请参考here对于我之前的背景信息问题。按照answer建议来自纳西姆·本。我使用函数式 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 链接Predict_classes() 不可用。所以我的问题是我可以尝试其他选择吗?


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

  1. 切勿使用predict_proba Keras对于版本。Here你可以找到原因。
  2. 大多数用于将预测转化为类别的方法都没有考虑您的数据统计信息。在图像分割的情况下 - 通常检测对象比检测背景更重要。因此,我建议您使用从精确召回率每个类别的曲线。在这种情况下 - 您需要设置一个阈值precision == recall(或者尽可能接近)。获得阈值后 - 您需要编写用于类别预测的自定义函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Predict_classes() 的函数式 API Keras 替代解决方案 的相关文章

随机推荐