keras源码全解析

前言

做为一个tensorflow的忠实用户,一直对keras有一种‘嫌弃’之情,网上大部分人对keras的评价也是low+灵活性差+慢,直到tf2.0决定添加keras的api后,我改变了自己的看法,keras简洁、结构清晰、代码易读,和sklearn保持一致的api,自定义层也能解决其灵活性的问题,keras一开始是基于theno开发的,tf的确慢一些,不过现在的版本已经改进了许多,速度方面也不用再担心。其次相比自己写的tf代码,keras的代码日志输出更加合理,总感觉自己对tf的封装还是做的不尽如人意,这也是我为什么打算出一个keras源码分析专题的原因。后续的文章,会对所有keras的代码进行分析讲解,并结合一些简单的demo。那么,废话不多说let’s go。

keras的总体结构

在这里插入图片描述

先看下keras源码的总体结构,其代码量并不多,毕竟只是其他底层库的封装,我们一个一个模块的来看。

  • applications,一些常用的预训练好的模型,可以直接拿过来做预测、特征提取、或者微调,模型包括了
    在这里插入图片描述
    可惜没有nlp方面的模型,不知道以后会不会把bert、xlnet这些模型添加进去。

  • backend,keras是一个对底层api进行了进一步封装的高级库,backend表示的即是keras调用的底层库,其目前包括了三个底层库,分别是tensorflowtheanoCNTK,官方也表示未来还会添加更多。如果已经运行过keras,那么会在$HOME/.keras/keras.json找到一个配置文件,默认配置如下:

{
    "image_data_format": "channels_last",
    "epsilon": 1e-07,
    "floatx": "float32",
    "backend": "tensorflow"
}

其中backend就是在此处配置。

  • datasets,keras自带的数据集,包括cifar10,imdb等等数据获取的脚本
  • engine,Layer类的实现,也是keras最核心的内容
  • layers,一些常用的layer,对engine的进一步封装
  • legacy
  • preprocessing,一些预处理代码
  • utils,工具类
  • wrappers,对fit、predict等函数的包装

以上模块我会选择比较重要的去进行详细的源码讲解,持续更新中。

Layer源码解析

Input源码解析

Dense源码解析

  • 10
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
图书可以从下面的链接下载 http://download.csdn.net/detail/u013003382/9832573 Deep Learning with Keras by Antonio Gulli English | 26 Apr. 2017 | ASIN: B06Y2YMRDW | 318 Pages | AZW3 | 10.56 MB Key Features Implement various deep-learning algorithms in Keras and see how deep-learning can be used in games See how various deep-learning models and practical use-cases can be implemented using Keras A practical, hands-on guide with real-world examples to give you a strong foundation in Keras Book Description This book starts by introducing you to supervised learning algorithms such as simple linear regression, the classical multilayer perceptron and more sophisticated deep convolutional networks. You will also explore image processing with recognition of hand written digit images, classification of images into different categories, and advanced objects recognition with related image annotations. An example of identification of salient points for face detection is also provided. Next you will be introduced to Recurrent Networks, which are optimized for processing sequence data such as text, audio or time series. Following that, you will learn about unsupervised learning algorithms such as Autoencoders and the very popular Generative Adversarial Networks (GAN). You will also explore non-traditional uses of neural networks as Style Transfer. Finally, you will look at Reinforcement Learning and its application to AI game playing, another popular direction of research and application of neural networks. What you will learn Optimize step-by-step functions on a large neural network using the Backpropagation Algorithm Fine-tune a neural network to improve the quality of results Use deep learning for image and audio processing Use Recursive Neural Tensor Networks (RNTNs) to outperform standard word embedding in special cases Identify problems for which Recurrent Neural Network (RNN) solutions are suitable Explore the process required to implement Autoencoders Evolve a deep neural network using reinforcement learning About the Author Antonio Gulli is a software executive and business leader with a passion for establishing and managing global technological talent, innovation, and execution. He is an expert in search engines, online services, machine learning, information retrieval, analytics, and cloud computing. So far, he has been lucky enough to gain professional experience in four different countries in Europe and managed people in six different countries in Europe and America. Antonio served as CEO, GM, CTO, VP, director, and site lead in multiple fields spanning from publishing (Elsevier) to consumer internet (Ask.com and Tiscali) and high-tech R&D (Microsoft and Google). Sujit Pal is a technology research director at Elsevier Labs, working on building intelligent systems around research content and metadata. His primary interests are information retrieval, ontologies, natural language processing, machine learning, and distributed processing. He is currently working on image classification and similarity using deep learning models. Prior to this, he worked in the consumer healthcare industry, where he helped build ontology-backed semantic search, contextual advertising, and EMR data processing platforms. He writes about technology on his blog at Salmon Run. Table of Contents Neural Networks Foundations Keras Installation and API Deep Learning with ConvNets Generative Adversarial Networks and WaveNet Word Embeddings Recurrent Neural Network — RNN Additional Deep Learning Models AI Game Playing Conclusion

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值