http://www.360doc.com/content/17/0415/12/1489589_645772879.shtml

http://adventuresinmachinelearning.com/keras-tutorial-cnn-11-lines/

https://www.zhihu.com/question/42139290

To create a callback we create an inherited class which inherits from keras.callbacks.Callback:

class AccuracyHistory(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self.acc = [] def on_epoch_end(self, batch, logs={}):
self.acc.append(logs.get('acc'))

The Callback super class that the code above inherits from has a number of methods that can be overridden in our callback definition such as on_train_begin, on_epoch_end, on_batch_begin and on_batch_end.  The name of these methods are fairly self explanatory, and represent moments in the training process where we can “do stuff”.  In the code above, at the beginning of training we initialise a list self.acc = [] to store our accuracy results.  Using the on_epoch_end() method, we can extract the variable we want from the logs, which is a dictionary that holds, as a default, the loss and accuracy during training.  We then instantiate this callback like so:

history = AccuracyHistory()

Now we can pass history to the .fit() function using the callback parameter name.  Note that .fit() takes a list for the callback parameter, so you have to pass it history like this: [history].  To access the accuracy list that we created after the training is complete, you can simply call history.acc, which I then also plotted:

plt.plot(range(1,11), history.acc)
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.show()

Hope that helps.  Have fun using Keras.

最新文章

  1. 有关Asp.net 中数据请求的处理的新认知:利用httpHandlers
  2. iOS - NSError用法规范
  3. Scala 中的函数式编程基础(一)
  4. linux下proc里关于磁盘性能的参数
  5. 通过Jmeter完成WebTours的性能测试
  6. 编译spock proxy
  7. Oozie和Azkaban的技术选型和对比
  8. GLSL实现简单硬件Anisotrop Lighting 【转】
  9. 软件开发中的单一职责(转至INFOQ)
  10. c++类的构造函数与析构函数
  11. perl的USE和require
  12. 【转】PHP代码审计
  13. python xlsxwriter库生成图表的应用
  14. CSS背景图片
  15. Fib数列2 费马小定理+矩阵乘法
  16. .NET Core开发日志——Edge.js
  17. git中 .ignore文件的配置 忽略不想上传的文件
  18. 使用SimpleMDE富文本编辑器
  19. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution
  20. 20145329 《网络对抗技术》PC平台逆向破解

热门文章

  1. Java问题汇总
  2. tensorflow入门笔记(五) name_scope和variable_scope
  3. 我想要得那块牌—记烟台大学第一届"ACM讲堂"
  4. RN九宫格
  5. 基于TensorFlow的简单验证码识别
  6. [redis]redis常用
  7. [css]table的拆分
  8. docker容器多服务(不推荐)
  9. Python 全栈开发十一 深浅拷贝
  10. Spring Hibernate Transaction示例