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. selenium自动化爬虫测试

    import time from selenium import webdriver from lxml import etree from selenium.webdriver import Act ...

  2. Flask的上下文管理

    flask上下文管理 1.运用的知识点 val = threading.local() def task(arg): #threading.local() val.xxx=123 #内部,获取当前线程 ...

  3. Linux 常用命令(根据自己的理解随时更新)

    1. linux 目录解释系统启动必须: /boot:存放的启动 Linux 时使用的内核文件,包括连接文件以及镜像文件. /etc:存放所有的系统需要的配置文件和子目录列表,更改目录下的文件可能会导 ...

  4. prometheus学习系列七: Prometheus promQL查询语言

    Prometheus promQL查询语言 Prometheus提供了一种名为PromQL (Prometheus查询语言)的函数式查询语言,允许用户实时选择和聚合时间序列数据.表达式的结果既可以显示 ...

  5. Redis的内存分配

    内存分配 Redis进程的内存消耗主要包括:自身内存 + 对象内存 + 缓冲内存 + 内存碎片.1 自身内存 Redis自身内存消耗非常少,通常used_memory在800KB左右,used_mem ...

  6. Odoo仪表盘详解

    转载请注明原文地址:https://www.cnblogs.com/ygj0930/p/10826324.html 一:仪表盘与看板的区别 kanban:kanban是一种视图类型,卡片式视图.可以为 ...

  7. Nginx配置文件、优化详解

    上篇<编译安装nginx>已将nginx安装好,这篇写nginx配置文件和部分优化参数. 查看nginx的配置文件路径,可以使用nginx配置文件检查命令nginx -t: [root@n ...

  8. dfs 正则表达式

    192. 通配符匹配 中文 English 判断两个可能包含通配符“?”和“*”的字符串是否匹配.匹配规则如下: '?' 可以匹配任何单个字符. '*' 可以匹配任意字符串(包括空字符串). 两个串完 ...

  9. excel打开提示 文件格式和扩展名不匹配。文件可能已损坏或不安全。除非您信任其来源,否则请勿打开。是否仍要打开它?

    有的时候打开xls文档时,会提示“文件格式和扩展名不匹配.文件可能已损坏或不安全.除非您信任其来源,否则请勿打开.是否仍要打开它?” 遇到这种情况,我们需要 打开“注册表编辑器” win键+R键,打开 ...

  10. opencv想到的

    opencv是用C++写的库,包了多种语言接口,包括C,C++,python,java等. OpenCV 是一个开放源代码的计算机视觉库,目前在科研和开发中被广泛使用.OpenCV 由一系列 C 函数 ...