Keras & Theano 输出中间层结果
Keras & Theano get output of an intermediate layer
1.使用函数模型API,新建一个model,将输入和输出定义为原来的model的输入和想要的那一层的输出,然后重新进行predict.
import seaborn as sbn
import pylab as plt
import theano
from keras.models import Sequential
from keras.layers import Dense,Activation from keras.models import Model model = Sequential()
model.add(Dense(32, activation='relu', input_dim=100))
model.add(Dense(16, activation='relu',name="Dense_1"))
model.add(Dense(1, activation='sigmoid',name="Dense_2"))
model.compile(optimizer='rmsprop',
loss='binary_crossentropy',
metrics=['accuracy']) # Generate dummy data
import numpy as np
#假设训练和测试使用同一组数据
data = np.random.random((1000, 100))
labels = np.random.randint(2, size=(1000, 1)) # Train the model, iterating on the data in batches of 32 samples
model.fit(data, labels, epochs=10, batch_size=32)
#已有的model在load权重过后
#取某一层的输出为输出新建为model,采用函数模型
dense1_layer_model = Model(inputs=model.input,
outputs=model.get_layer('Dense_1').output)
#以这个model的预测值作为输出
dense1_output = dense1_layer_model.predict(data) print(dense1_output.shape)
print(dense1_output[0])
#这是一个theano的函数
dense1 = theano.function([model.layers[0].input],model.layers[1].output,allow_input_downcast=True)
dense1_output = dense1(data) #visualize these images's FC-layer feature
print(dense1_output[0])
效果应该是一样的。
来源:https://blog.csdn.net/hahajinbu/article/details/77982721
Keras & Theano 输出中间层结果的更多相关文章
- Hi3559AV100 NNIE开发(5)mobilefacenet.wk仿真成功量化及与CNN_convert_bin_and_print_featuremap.py输出中间层数据对比过程
前面随笔给出了NNIE开发的基本知识,下面几篇随笔将着重于Mobilefacenet NNIE开发,实现mobilefacenet.wk的chip版本,并在Hi3559AV100上实现mobilefa ...
- Hi3559AV100 NNIE开发(7) Ruyistudio 输出mobileface_func.wk与板载运行mobileface_chip.wk输出中间层数据对比
前面随笔讲了关于NNIE的整个开发流程,并给出了Hi3559AV100 NNIE开发(5)mobilefacenet.wk仿真成功量化及与CNN_convert_bin_and_print_featu ...
- keras输出中间层结果,某一层的权重、偏置
转载:https://blog.csdn.net/hahajinbu/article/details/77982721 from keras.models import Sequential,Mode ...
- keras+theano+tensorflow+darknet
keras 安装: 最好在anaconda的虚拟环境下搭建: conda create -n 环境名 python=3.6 进入环境: source activate 环境名 安装keras: pip ...
- keras 多输出问题
转自:https://github.com/Xls1994/DeepLearningCode/blob/master/Keras/HedgeScope/multiOutputLSTM.py
- 开源项目(4-2)手势识别-Keras/Theano/OpenCV实现的CNN手势识别
https://github.com/asingh33/CNNGestureRecognizer 我提供了两种捕获模式: 二进制模式:在这里我首先将图像转换为灰度,然后应用高斯模糊效果和自适应阈值滤波 ...
- 关于深度学习框架 TensorFlow、Theano 和 Keras
[TensorFlow] ——( https://morvanzhou.github.io/tutorials/machine-learning/tensorflow/) 1.TensorFlow是啥 ...
- Keras + Ubuntu环境搭建
安装Theano (环境参数:Ubuntu 16.04.2 Python 2.7) 安装 numpy 和 scipy 1.sudo apt-get install python-numpy pyth ...
- Windows7配置GPU和Theano编程环境
可参考Windows安装Theano官方教程: http://deeplearning.net/software/theano/install_windows.html#install-windows ...
随机推荐
- 抓取出现时间3s后消失的元素
背景:日常自动化脚本编写中,可能需要定位,获取元素的位置,通常会遇到一种元素,只出现几秒,几秒后慢慢消失的,这个时候,如果要抓取这个提示,如果和它比手速,当你手速比较快,可以箭头抓取到,但当这个元素的 ...
- Swift 中@available 和 #available
Swift 2.0 中,引入了可用性的概念.对于函数,类,协议等,可以使用@available声明这些类型的生命周期依赖于特定的平台和操作系统版本.而#available用在判断语句中(if, gua ...
- Java之IO(十)Reader和Writer
转载请注明源出处:http://www.cnblogs.com/lighten/p/7071733.html 1.前言 之前的章节已经将Java8的io包中的字节流介绍完毕了.本章开始介绍Java的I ...
- Servlet基础知识点
一.web.xml 的加载顺序是: ServletContext-> context-param ->listener -> filter -> servlet,而同个类型之间 ...
- 【C#小知识】C#中一些易混淆概念总结(六)---------解析里氏替换原则,虚方法 分类: C# 2014-02-08 01:53 1826人阅读 评论(0) 收藏
目录: [C#小知识]C#中一些易混淆概念总结--------数据类型存储位置,方法调用,out和ref参数的使用 [C#小知识]C#中一些易混淆概念总结(二)--------构造函数,this关键字 ...
- Android 开发工具类 24_getHtml
获取网页(JSP)源码 import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; impo ...
- Python -- Gui编程 -- Qt库的使用 -- 配置资源文件
1.源文件(qtRes.py) import sys from PyQt4 import QtCore, QtGui, uic class MyDialog(QtGui.QDialog): def _ ...
- 机器学习--boosting家族之XGBoost算法
一.概念 XGBoost全名叫(eXtreme Gradient Boosting)极端梯度提升,经常被用在一些比赛中,其效果显著.它是大规模并行boosted tree的工具,它是目前最快最好的开源 ...
- Linux-文件和目录属性
文件系统的是用来组织和排列文件存取的,所以它是可见的,在Linux中,我们可以通过ls等工具来查看其结构,在Linux系统中,见到的都是树形结构:比如操作系统安装在一个文件系统中,他表现为由/ 起始的 ...
- 面试:http协议
转自:http://www.cnblogs.com/ranyonsue/p/5984001.html#undefined HTTP简介 HTTP协议是Hyper Text Transfer Proto ...