logo
Loading...

出現NoneType' object is not subscriptable錯誤 - Cupoy

TypeError                                 Tracebac...

ml100-3,ml100-3-d88

出現NoneType' object is not subscriptable錯誤

2019/12/07 上午 11:52
機器學習共學討論版
骑士
觀看數:107
回答數:2
收藏數:0
ml100-3
ml100-3-d88



TypeError                                 Traceback (most recent call last)
<ipython-input-8-de2a5ca0ea56> in <module>
     9           validation_data=(x_test, y_test),
    10           shuffle=True,
---> 11           callbacks=[log_f1sc]
    12          )
    13 


....


16     def on_epoch_end(self, epoch, logs = {}, thres=0.5):
    17         logs = logs or {}
---> 18         y_true = self.validation_data[1].argmax(axis = 1)
    19         y_pred = self.model.predict(self.validation_data[0])
    20         y_pred = (y_pred[:, 1] >= thres) * 1

TypeError: 'NoneType' object is not subscriptable


备注:我是调用tensorflow.keras函数库。

回答列表

  • 2019/12/11 下午 11:08
    Seanyu.TW
    贊同數:0
    不贊同數:0
    留言數:0

    Hi, 因為你的 self.validation_data[1] 是 None, 建議你在函式裡面 print(self.validation_data[1])

  • 2020/07/31 下午 07:50
    Shengzhi Lin
    贊同數:0
    不贊同數:0
    留言數:0

    嗨,我發現在callback函數裡面沒辦法直接繼承model validation data,所以要在寫class的時候加進去,我的code如下所示: