Keras costum Callback. When generating precision recall I get an error in _flow_index

大憨熊 提交于 2020-01-14 19:58:54

问题


I'm training a binary classifier using Keras. I want to generate the precision_score and recall_score after each epoch in order to analyze the training more in depth. On the internet I found tutorials/help, such as:

  • https://medium.com/@thongonary/how-to-compute-f1-score-for-each-epoch-in-keras-a1acd17715a2

  • https://github.com/keras-team/keras/issues/2607

I found Accessing validation data within a custom callback which worked best for me since I'm using Keras fit_generator. It managed to compute precision and recall after each epoch. However, I think I do something wrong when creating the custom Callback. I get the following error message:

File "...\envs\keras\lib\site-packages\keras\preprocessing\image.py", line 845, in _flow_index
current_index = (self.batch_index * self.batch_size) % self.n

ZeroDivisionError: integer division or modulo by zero

My best guess is that the custom Callback inherits incorrectly from Keras.

Has anybody experienced this issue? Or do anyone know what I am missing?

UPDATE

I think I understand the error now. In Keras image.py current_index is divided by self.n. In the class named Iterator (in Keras) n is defined as

n: Integer, total number of samples in the dataset to loop over.

In other words, I understand it as that the network can't be fed with zero samples. I realized that my test set was empty (0 samples), hence the error message.

When corrected (fed the test set with data) the code worked fine :)

来源:https://stackoverflow.com/questions/50065411/keras-costum-callback-when-generating-precision-recall-i-get-an-error-in-flow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!