tensorflow keras analysis

code

from keras.models import Sequential

model = Sequential()

from keras.layers import Dense

model.add(Dense(units=64, activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax')) model.compile(loss='categorical_crossentropy',
optimizer='sgd',
metrics=['accuracy']) model.compile(loss=keras.losses.categorical_crossentropy,
optimizer=keras.optimizers.SGD(lr=0.01, momentum=0.9, nesterov=True)) # x_train and y_train are Numpy arrays --just like in the Scikit-Learn API.
model.fit(x_train, y_train, epochs=5, batch_size=32) # Alternatively, you can feed batches to your model manually:
model.train_on_batch(x_batch, y_batch) # Evaluate your performance in one line: loss_and_metrics = model.evaluate(x_test, y_test, batch_size=128) # Or generate predictions on new data: classes = model.predict(x_test, batch_size=128)

Q: where is Sequential defined?

A:

From https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/models.py

from tensorflow.python.keras.engine import sequential
Sequential = sequential.Sequential # pylint: disable=invalid-name

We get the definition of Sequential class From https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/engine/sequential.py

@keras_export('keras.models.Sequential', 'keras.Sequential')
class Sequential(training.Model):
...
def add(self, layer):
...
... batch_shape, dtype = training_utils.get_input_shape_and_dtype(layer)
if batch_shape:
# Instantiate an input layer.
x = input_layer.Input(
batch_shape=batch_shape, dtype=dtype, name=layer.name + '_input')
# This will build the current layer
# and create the node connecting the current layer
# to the input layer we just created.
layer(x)
set_inputs = True

Q: where is compile()?

from tensorflow.python.keras.engine import training

we find the definition of Model class from file:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/keras/engine/training.py

tensorflow keras analysis的更多相关文章

  1. 【学习总结】win7使用anaconda安装tensorflow+keras

    tips: Keras是一个高层神经网络API(高层意味着会引用封装好的的底层) Keras由纯Python编写而成并基Tensorflow.Theano以及CNTK后端. 故先安装TensorFlo ...

  2. [转] 理解CheckPoint及其在Tensorflow & Keras & Pytorch中的使用

    作者用游戏的暂停与继续聊明白了checkpoint的作用,在三种主流框架中演示实际使用场景,手动点赞. 转自:https://blog.floydhub.com/checkpointing-tutor ...

  3. [AI][tensorflow][keras] archlinux下 tersorflow and keras 安装

    tensorflow TensorFlow is an open-source machine learning library for research and production. https: ...

  4. 时间序列预测——Tensorflow.Keras.LSTM

    1.测试数据下载 https://datamarket.com/data/set/22w6/portland-oregon-average-monthly-bus-ridership-100-janu ...

  5. Jetson tx2的tensorflow keras环境搭建

    其实我一直都在想,搞算法的不仅仅是服务,我们更是要在一个平台上去实现服务,因此,在工业领域,板子是很重要的,它承载着无限的机遇和挑战,当然,我并不是特别懂一些底层的东西,但是这篇博客希望可以帮助有需要 ...

  6. [开发技巧]·TensorFlow&Keras GPU使用技巧

    [开发技巧]·TensorFlow&Keras GPU使用技巧 ​ 1.问题描述 在使用TensorFlow&Keras通过GPU进行加速训练时,有时在训练一个任务的时候需要去测试结果 ...

  7. tensor搭建--windows 10 64bit下安装Tensorflow+Keras+VS2015+CUDA8.0 GPU加速

    windows 10 64bit下安装Tensorflow+Keras+VS2015+CUDA8.0 GPU加速 原文见于:http://www.jianshu.com/p/c245d46d43f0 ...

  8. 100天搞定机器学习|day39 Tensorflow Keras手写数字识别

    提示:建议先看day36-38的内容 TensorFlow™ 是一个采用数据流图(data flow graphs),用于数值计算的开源软件库.节点(Nodes)在图中表示数学操作,图中的线(edge ...

  9. 100天搞定机器学习|day40-42 Tensorflow Keras识别猫狗

    100天搞定机器学习|1-38天 100天搞定机器学习|day39 Tensorflow Keras手写数字识别 前文我们用keras的Sequential 模型实现mnist手写数字识别,准确率0. ...

随机推荐

  1. 数据结构与算法17—B树(B、B+、B*)

    B树 B-树,就是B树,B树的原英文名是B-tree,所以很多翻译为B-树,就会很多人误以为B-树是一种树.B树是另外一种树.其实,B-tree就是B树. B-树的定义 B树(B-tree)是一种树状 ...

  2. 【VUE】图片预览放大缩小插件

    From: https://www.jianshu.com/p/e3350aa1b0d0 在看项目时,突然看到预览图片的弹窗,感觉好僵硬,不能放大,不能切换,于是便在网上找下关于图片预览的插件,有找到 ...

  3. 《快活帮》第九次团队作业:【Beta】Scrum meeting 3

    项目 内容 这个作业属于哪个课程 2016计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十三 团队作业9:BETA冲刺与团队项目验收 团队名称 快活帮 作业学习目标 (1)掌 ...

  4. G6 学习资料

    G6 学习资料 网址 G6 1.x API 文档 http://antvis.github.io/g6/doc/index.html 官方demo列表 https://github.com/antvi ...

  5. Template Function

    // TemplateFunction.cpp : Defines the entry point for the console application. // #include "std ...

  6. accept返回的socket的端口号和连接socket一样的!!! socket绑定信息结构

    今天与同学争执一个话题:由于socket的accept函数在有客户端连接的时候产生了新的socket用于服务该客户端,那么,这个新的socket到底有没有占用一个新的端口? 讨论完后,才发现,自己虽然 ...

  7. RabbitMQ六种队列模式-发布订阅模式

    前言 RabbitMQ六种队列模式-简单队列RabbitMQ六种队列模式-工作队列RabbitMQ六种队列模式-发布订阅 [本文]RabbitMQ六种队列模式-路由模式RabbitMQ六种队列模式-主 ...

  8. MongoDB 命令速查表

    MongoDB  是一个面向文档可扩展的高性能开源数据库,典型的应用场景有网页数据,缓存,代替文档存储等. 命令的记忆和使用是一门基本功,这里准备了速查表,可以做案头手册. 库操作 切换或使用数据库 ...

  9. MongoDB Shell db.runCommand

    db.runCommand()示例 我们使用MongoDB Shell登录到mongos,添加Shard节点 [root@100 shard]# /usr/local/mongoDB/bin/mong ...

  10. linux 下安装git的步骤方法

    ①.获取github最新的Git安装包下载链接,进入Linux服务器,执行下载,命令为: wget https://github.com/git/git/archive/v2.17.0.tar.gz  ...