keras上手之:与tensorflow混合编程

这篇博客介绍了如何在Keras高级API和TensorFlow低级API之间进行混合编程。通过示例展示如何利用Keras建模,TensorFlow进行输入输出,并在训练过程中使用TensorFlow的session和功能如tensorboard,展示loss历史曲线,实现模型的可视化监控。
摘要由CSDN通过智能技术生成

tensorflow具备许多优秀的函数和功能,比如tensorboard,keras作为tensorflow的高级API, 封装很多tensorflow的代码,使得代码模块化,非常方便。
当然,由于keras的模型和层与tensorflow的张量高度兼容,可以用keras建模,用tensorflow输入输出。
例如下面的例子:

import tensorflow as tf
from keras import backend as K
from keras.layers import Dense
from keras.objectives import categorical_crossentropy
from keras.metrics import categorical_accuracy as accuracy
from tensorflow.examples.tutorials.mnist import input_data
# create a tf session,and register with keras。
sess = tf.Session()
K.set_session(sess)

# this place holder is the same with input layer in keras
img = tf.placeholder(tf.float32, shape=(None, 784))
# keras layers can be called on tensorflow tensors
x = Dense(128, activation='relu')(img)
x = Dense(128, activation='relu')(x)
preds = Dense(10, activation=
  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值