keras 与tensorflow 混合使用
keras 与tensorflow 混合使用
tr:nth-child(odd) > td,
.table-striped tbody > tr:nth-child(odd) > th {
background-color: #f9f9f9;
}
tr { page-break-inside: avoid; }
.story_image_container{
page-break-inside: avoid;
}
.xsj_underline{
page-break-after: always;
visibility: hidden;
}
.table-celled.table tr td,.table-celled.table tr th {
border-left: 1px solid rgba(34,36,38,.1)
}
.table-celled.table tr td:first-child,.table-celled.table tr th:first-child {
border-left: none
}
.toc ul {
list-style: none;
}
p {
line-height: 1.6;
}
body>p {
margin-bottom: 1.8em;
}
body>p>img.center,
body>p>a>img.center {
display: block;
margin: 0 auto;
background-color: rgba(128,128,128,0.3);
}
body {
font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, 'Hiragino Sans GB', STHeiti, "Microsoft YaHei", "微软雅黑", 'WenQuanYi Micro Hei', STXihei, "华文细黑", Heiti, "黑体", SimSun, "宋体", Song, sans-serif;
font-size: 18px;
line-height: 1.33;
font-weight: 100;
// line-height: 1.8em;
color: #2f2f2f;
word-wrap: break-word;
word-break: break-word;
}
em.cjk_emphasis{
font-style: normal;
font-family: Georgia,"Times New Roman",Times,"楷体","AR PL UKai CN", "NSimSun","Songti SC","SimSun",serif!important;
}
body dt,
body dd {
line-height: 1.35em;
}
body code, body .xiaoshujiang_code {
// background-color: #D6DBDF;
border: 0;
border-radius: 4px;
// color: #2C3E50;
font-size: 90%;
// padding: 2px 4px;
}
code {
background-color: rgba(214, 219, 223, 0.28);
border-radius: 4px;
color: #2C3E50;
padding: 2px 4px;
}
.xiaoshujiang_code ol{
margin-bottom: 0px;
}
body h1 {
line-height: 1.6;
}
body h2 {
line-height: 1.1;
}
body h3 {
line-height: 1.1;
}
.hljs, .hljs * {
overflow: visible !important;
}
/**
* Treeview syntax highlighting based on highlight.js
* Copyright (c) 2014-2015, Asciidocfx Team, (MIT Licensed)
* https://github.com/asciidocfx/highlight-treeview.js
*/
.language-treeview.hljs{
position: relative;
}
.hljs-folder,
.hljs-hiddenfile,
.hljs-file {
position: relative;
vertical-align: top;
display: inline-block;
height: 16px;
}
.hljs-folder:before,
.hljs-file:before,
.hljs-hiddenfile:before {
top: 0;
content: '';
width: 14px;
height: 12px;
margin-top: 0px;
margin-right: 3px;
position: relative;
display: inline-block;
background-size: 14px;
background-repeat: no-repeat;
}
.hljs-file:before,
.hljs-hiddenfile:before {
height: 14px;
margin-left: 1px;
}
.hljs-hiddenfile {
opacity: 0.6;
}
.hljs-file.photo:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c5";
}
.hljs-file.plain:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f016";
}
.hljs-file.source:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c9";
}
.hljs-file.archive:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c6";
}
.hljs-file.audio:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c7";
}
.hljs-file.video:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c8";
}
.hljs-file.pdf:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c1";
}
.hljs-file.xls:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c3";
}
.hljs-file.doc:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c2";
}
.hljs-file.ppt:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c4";
}
.hljs-folder:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f114";
}
.hljs-hiddenfile:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f016";
}
.hljs-tvline {
margin-left: 6px;
position: absolute;
text-indent: -99em;
padding-bottom: 8px;
vertical-align: top;
display: inline-block;
border-left-width: 1px;
border-left-style: solid;
border-left-color: rgb(94, 144, 117);
}
.hljs-folder-branch {
width: 8px;
height: 8px;
margin-top: -1px;
margin-left: 6px;
text-indent: -99em;
position: relative;
vertical-align: top;
display: inline-block;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(94, 144, 117);
}
.hljs-folder-branch.win {
width: 14px;
margin-right: 2px;
}
.hljs-folder-last-branch {
height: 7px;
width: 7px;
margin-left: 6px;
text-indent: -99em;
position: relative;
vertical-align: top;
display: inline-block;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(94, 144, 117);
border-left-width: 1px;
border-left-style: solid;
border-left-color: rgb(94, 144, 117);
}
.hljs-folder-last-branch.win {
width: 13px;
margin-right: 2px;
}
/**
* Treeview syntax highlighting based on highlight.js
*/
.mark{
border: 0;
background-color: rgba(221, 243, 231, 0.4);
border-radius: 4px;
color: #29754d;
font-size: 90%;
padding: 2px 4px;
}
.line_mark{
border: 1px dashed #3A4C42;
margin-top: 2px;
}
code .mark, .xiaoshujiang_code .mark{
border-radius: 0px;
font-size: initial;
padding: initial;
}
a.attachment{
background-color: #ecf0f3;
border: 1px solid #bec6cb;
display: inline-block;
padding: 5px;
margin: 2px;
min-width: 250px;
}
a.attachment i.fa{
font-size: 3em;
float: left;
margin-right: 0.2em;
}
a.attachment .filename{
vertical-align: top;
text-align: left;
font-weight: bold;
}
a.attachment .filesize{
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
opacity: .6;
font-size: 80%;
white-space: nowrap;
}
.checkbox .checked{
text-decoration: line-through;
}
.flow-chart, .sequence-diagram{
text-align: center;
}
.plot, .plot-image{
text-align: center;
min-height: 200px;
min-width: 200px;
}
pre, .xiaoshujiang_pre {
line-height: initial !important;
word-wrap: break-word;
word-break: break-word;
tab-size: 4;
white-space: pre-wrap;
}
.xiaoshujiang_code_container pre{
margin: 0px;
}
.xiaoshujiang_code_container.xiaoshujiang_code_chunk{
box-shadow: 0 0 0 1px #A3C293 inset,0 0 0 0 transparent;
margin: 1em 0;
padding: 1em;
}
.xiaoshujiang_code_container.xiaoshujiang_code_chunk_hide_code{
box-shadow: initial;
padding: initial;
padding-bottom: 2em;
}
.xiaoshujiang_code_container .out_put{
box-shadow: 0 0 0 1px #A3C293 inset,0 0 0 0 transparent;
margin: 1em 0;
background-color: #FCFFF5;
color: #2C662D;
padding: 1em;
}
.xiaoshujiang_code_container .out_put_error{
background-color: #FFF6F6;
color: #9F3A38;
margin: 1em 0;
box-shadow: 0 0 0 1px #E0B4B4 inset,0 0 0 0 transparent;
padding: 1em;
}
.xiaoshujiang_pre {
font-family: monospace;
}
.story_align_left, .story_align_left .story_image_container {
text-align: left;
}
.story_align_right, .story_align_right .story_image_container {
text-align: right;
}
.story_align_center, .story_align_center .story_image_container {
text-align: center;
}
.story_align_justify, .story_align_justify .story_image_container {
text-align: justify;
}
/**
* code line nums
*/
code.hljs.code_linenums, .xiaoshujiang_code.hljs.code_linenums{
position: relative;
}
.ol_linenums{
padding: 0px;
margin-left: 30px;
border-left: 1px solid #e0e0e0;
}
.li_linenum{
margin-left: 10px;
list-style: none;
counter-increment: lines 1;
}
.li_linenum.li_list_style{
list-style: inherit;
margin-left: 5px;
}
.li_linenum:before, .li_linenum_before_span{
content: counter(lines, decimal);
position: absolute;
left: 0px;
text-align: center;
width: 2.5em;
vertical-align: top;
}
.li_linenum_before_span_hide{
display: none;
}
.xiaoshujiang_code .code_line_break_hack{
margin:0;
border:0;
border-top:0;
border-bottom:0;
}
/**
* code line nums
*/
.mathjax-container{
text-align: center;
}
div.mathjax{
max-width: 600px;
margin: 0 auto;
font-size: 14px;
}
text{
font-size: 14px;
}
/**
* block image
*/
.story_image_container{
text-align: center;
}
.story_image_container>.story_image{
display: inline-block;
position: relative;
max-width: 80%;
}
.story_image_caption{
border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 10px;
}
.story_image_blank_caption{
border-bottom: 0px;
}
/**
.story_image:before, .story_image:after{
content: '';
position: absolute;
z-index: -2;
bottom: 13px;
left: 10px;
width: 50%;
height: 20%;
border-radius: 10px/90px;
box-shadow: 0 15px 10px rgba(0,0,0,0.7);
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.story_image:after {
right: 10px;
left: auto;
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-ms-transform: rotate(3deg);
-o-transform: rotate(3deg);
transform: rotate(3deg);
}
**/
.story_image>img{
border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);
}
.story_inline_image>img{
max-width: 50%;
vertical-align: bottom;
}
.story_remote_resource_block{
text-align: center;
}
.xiaoshujiang_code_container {
margin: 1em 0px;
position: relative;
padding-bottom: 2em;
}
.xiaoshujiang_code_title_container{
font-size: 70%;
opacity: 0.5;
}
.xiaoshujiang_code_title_container>.xiaoshujiang_code_infos{
float: right;
}
.task-list-item{
list-style: none;
}
.task-list-item.li_list_style{
list-style:inherit;
}
.task-list-item>input{
margin: 0 0 0 -20px;
}
.video_container{
width: 100%;
display: table;
text-align: center;
position: relative;
padding-bottom: 56.25%!important;
}
.slideshare_container .inner{
position: relative;
width: 100%;
}
.slideshare_container .inner iframe{
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.video_container iframe{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
vertical-align: middle;
}
kbd{
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.blank_anchor_id {
float: left;
}
.blank_anchor_id {
visibility: hidden;
}
.blank_anchor_id:before {
content: 'a';
}
blockquote footer{
margin: 1em 0;
font-style: italic;
}
blockquote footer cite {
margin: 0 1em;
}
/*wavedrom start*/
.wavedrom_svg text, .wavedrom_svg_defs text {
font-size:11pt;
font-style:normal;
font-variant:normal;
font-weight:normal;
font-stretch:normal;
text-align:center;
fill-opacity:1;
font-family:Helvetica
}
.wavedrom_svg .muted, .wavedrom_svg_defs .muted {
fill:#aaa
}
.wavedrom_svg .warning, .wavedrom_svg_defs .warning {
fill:#f6b900
}
.wavedrom_svg .error, .wavedrom_svg_defs .error {
fill:#f60000
}
.wavedrom_svg .info, .wavedrom_svg_defs .info {
fill:#0041c4
}
.wavedrom_svg .success, .wavedrom_svg_defs .success {
fill:#00ab00
}
.wavedrom_svg .h1, .wavedrom_svg_defs .h1 {
font-size:33pt;
font-weight:bold
}
.wavedrom_svg .h2, .wavedrom_svg_defs .h2 {
font-size:27pt;
font-weight:bold
}
.wavedrom_svg .h3, .wavedrom_svg_defs .h3 {
font-size:20pt;
font-weight:bold
}
.wavedrom_svg .h4, .wavedrom_svg_defs .h4 {
font-size:14pt;
font-weight:bold
}
.wavedrom_svg .h5, .wavedrom_svg_defs .h5 {
font-size:11pt;
font-weight:bold
}
.wavedrom_svg .h6, .wavedrom_svg_defs .h6 {
font-size:8pt;
font-weight:bold
}
.wavedrom_svg_defs .s1 {
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
.wavedrom_svg_defs .s2 {
fill:none;
stroke:#000;
stroke-width:0.5;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
.wavedrom_svg_defs .s3 {
color:#000;
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:1,3;
stroke-dashoffset:0;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s4 {
color:#000;
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none;
stroke-dashoffset:0;
marker:none;
visibility:visible;
display:inline;
overflow:visible
}
.wavedrom_svg_defs .s5 {
fill:#fff;
stroke:none
}
.wavedrom_svg_defs .s6 {
color:#000;
fill:#ffffb4;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s7 {
color:#000;
fill:#ffe0b9;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s8 {
color:#000;
fill:#b9e0ff;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s9 {
fill:#000;
fill-opacity:1;
stroke:none
}
.wavedrom_svg_defs .s10 {
color:#000;
fill:#fff;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s11 {
fill:#0041c4;
fill-opacity:1;
stroke:none
}
.wavedrom_svg_defs .s12 {
fill:none;
stroke:#0041c4;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
/*wavedrom stop*/
.mermaid_svg{
font-family: monospace;
}
@media print{
body{
word-wrap: break-word;
word-break: break-word;
background: initial;
}
}
/*
Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull
*/
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #fdf6e3;
color: #657b83;
}
.hljs-comment,
.hljs-quote {
color: #93a1a1;
}
/* Solarized Green */
.hljs-keyword,
.hljs-selector-tag,
.hljs-addition {
color: #859900;
}
/* Solarized Cyan */
.hljs-number,
.hljs-string,
.hljs-meta .hljs-meta-string,
.hljs-literal,
.hljs-doctag,
.hljs-regexp {
color: #2aa198;
}
/* Solarized Blue */
.hljs-title,
.hljs-section,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class {
color: #268bd2;
}
/* Solarized Yellow */
.hljs-attribute,
.hljs-attr,
.hljs-variable,
.hljs-template-variable,
.hljs-class .hljs-title,
.hljs-type {
color: #b58900;
}
/* Solarized Orange */
.hljs-symbol,
.hljs-bullet,
.hljs-subst,
.hljs-meta,
.hljs-meta .hljs-keyword,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-link {
color: #cb4b16;
}
/* Solarized Red */
.hljs-built_in,
.hljs-deletion {
color: #dc322f;
}
.hljs-formula {
background: #eee8d5;
}
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
-->
keras 与tensorflow 混合使用
最近tensorflow更新了新版本,到1.4了。做了许多更新,当然重要的是增加了tf.keras. 毕竟keras对于模型搭建的方便大家都是有目共睹的。
喜欢keras风格的模型搭建而不喜欢tensorflow的方式。
但是个人觉得tensorflow的对于loss function定义的灵活性,还是非常便捷的,所以秉承着将二者的优势放在一起的想法,研究了一下如何混合的过程。
众所周知,keras搭建模型有两种方式,Sequential 和 function(?)这两种方式,而函数式搭建每一层返回的都是tensor结果,这就和tensorflow里面的对上了。所以做了如下初探:
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
# build module
img = tf.placeholder(tf.float32, shape=(None, 784))
labels = tf.placeholder(tf.float32, shape=(None, 10))
x = tf.keras.layers.Dense(128, activation='relu')(img)
x = tf.keras.layers.Dense(128, activation='relu')(x)
prediction = tf.keras.layers.Dense(10, activation='softmax')(x)
loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=prediction, labels=labels))
train_optim = tf.train.AdamOptimizer().minimize(loss)
mnist_data = input_data.read_data_sets('MNIST_data/', one_hot=True)
with tf.Session() as sess:
init = tf.global_variables_initializer()
sess.run(init)
for _ in range(1000):
batch_x, batch_y = mnist_data.train.next_batch(50)
sess.run(train_optim, feed_dict={img: batch_x, labels: batch_y})
acc_pred = tf.keras.metrics.categorical_accuracy(labels, prediction)
pred = sess.run(acc_pred, feed_dict={labels: mnist_data.test.labels, img: mnist_data.test.images})
print('accuracy: %.3f' % (sum(pred)/len(mnist_data.test.labels)))
keras 与tensorflow 混合使用的更多相关文章
- TensorFlow+Keras 03 TensorFlow 与 Keras 介绍
1 TensorFlow 架构图 1.1 处理器 TensorFlow 可以在CPU.GPU.TPU中执行 1.2 平台 TensorFlow 具备跨平台能力,Windows .Linux.Andro ...
- Reducing and Profiling GPU Memory Usage in Keras with TensorFlow Backend
keras 自适应分配显存 & 清理不用的变量释放 GPU 显存 Intro Are you running out of GPU memory when using keras or ten ...
- 在android上跑 keras 或 tensorflow 模型
https://groups.google.com/forum/#!topic/keras-users/Yob7mIDmTFs http://talc1.loria.fr/users/cerisara ...
- 使用C++部署Keras或TensorFlow模型
本文介绍如何在C++环境中部署Keras或TensorFlow模型. 一.对于Keras, 第一步,使用Keras搭建.训练.保存模型. model.save('./your_keras_model. ...
- 版本问题---keras和tensorflow的版本对应关系
keras和tensorflow的版本对应关系,可参考: Framework Env name (--env parameter) Description Docker Image Packages ...
- Keras---Virtualenv 下安装Keras (基于Tensorflow后端)
Python---Virtualenv 下安装Keras (基于Tensorflow后端) 一.Keras简介 https://keras-cn.readthedocs.io/en/latest ...
- Win10上安装Keras 和 TensorFlow(GPU版本)
一. 安装环境 Windows 10 64bit 家庭版 GPU: GeForce GTX1070 Python: 3.5 CUDA: CUDA Toolkit 8.0 GA1 (Sept 2016 ...
- SELU︱在keras、tensorflow中使用SELU激活函数
arXiv 上公开的一篇 NIPS 投稿论文<Self-Normalizing Neural Networks>引起了圈内极大的关注,它提出了缩放指数型线性单元(SELU)而引进了自归一化 ...
- 【tf.keras】TensorFlow 1.x 到 2.0 的 API 变化
TensorFlow 2.0 版本将 keras 作为高级 API,对于 keras boy/girl 来说,这就很友好了.tf.keras 从 1.x 版本迁移到 2.0 版本,需要修改几个地方. ...
随机推荐
- 《Typecript 入门教程》 3、接口
转载:<TypeScript 中文入门教程> 3.接口 介绍 TypeScript的核心原则之一是对值所具有的shape进行类型检查. 它有时被称做“鸭式辨型法”或“结构性子类型化”. 在 ...
- Android 蓝牙开发基本流程
此例子基于 android demo 对于一般的软件开发人员来说,蓝牙是很少用到的,尤其是Android的蓝牙开发,国内的例子很少 Android对于蓝牙开发从2.0版本的sdk才开始支持,而 ...
- Linux下安装Wine 运行、卸载 windows程序
资料 首页 https://www.winehq.org/ 安装 https://www.winehq.org/download/ 教程 https://www.winehq.org/document ...
- [转]linux uniq 命令详解
转自:http://blog.csdn.net/tianmohust/article/details/6997683 uniq 命令 文字 uniq 是LINUX命令 用途 报告或删除文件中重复的 ...
- java_基础知识_字符串练习题_计算两个字符串的最长公共字串长度
package tek; Java算法——求出两个字符串的最长公共字符串 /** * @Title: 问题:有两个字符串str1和str2,求出两个字符串中最长公共字符串. * @author 匹夫( ...
- Java final和static 修饰符
一.final final是不变的,最终的意思.可以用来修饰变量,方法,类. 1. 修饰变量 private final int a = 2; private final int b; // fina ...
- 项目管理01--使用Maven构建项目(纯干货)
目录 1. Maven基础知识 2. Maven实战.开发.测试.打包.部署一个Web项目 一.Maven基础知识 Maven坐标 Maven提供了一个中央仓库,里面包含了大量的开源软件的jar包,只 ...
- UI开发模式对比:JSP、Android、Flex
前一篇文章分析了Java平台下不同类型WEB框架对开发模式的影响,多数Java领域的WEB框架都是聚焦于服务端MVC的实现,这些框架对View的支持,通常是基于标准的JSP或类似JSP的模板技术如Fr ...
- 【PL/SQL】触发器示例:记录加薪
首先创建一张表,用于保存薪资变化情况: --创建加薪记录表 CREATE TABLE scott.raisedsalarylog ( empno ) NOT NULL PRIMARY KEY, --员 ...
- [Windows Server 2008] 安装网站伪静态
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IIS伪静 ...