使用python可视化特征层参数和特征图
来源:互联网 发布:国企程序员面试题 编辑:程序博客网 时间:2024/06/06 19:49
import numpy as npimport matplotlib.pyplot as pltimport osimport caffeimport sysimport pickleimport cv2caffe_root = 'deeplearning/regressionNet/sln/install/' deployPrototxt = 'deeplearning/regressionNet/sln/examples/regression_vggNet_deploy.prototxt'modelFile = 'deeplearning/regressionNet/sln/examples/_iter_1000.caffemodel'#meanFile = 'python/caffe/imagenet/ilsvrc_2012_mean.npy'
#网络初始化def initilize(): print 'initilize ... ' sys.path.insert(0, caffe_root + 'python') caffe.set_mode_gpu() #caffe.set_device(4) net = caffe.Net(deployPrototxt, modelFile,caffe.TEST) return net#取出网络中的params和net.blobs的中的数据def getNetDetails(image, net): # input preprocessing: 'data' is the name of the input blob == net.inputs[0] transformer = caffe.io.Transformer({'data': net.blobs['data'].data.shape}) transformer.set_transpose('data', (2,0,1)) #transformer.set_mean('data', np.load(caffe_root + meanFile ).mean(1).mean(1)) # mean pixel transformer.set_raw_scale('data', 255) # the reference model operates on images in [0,255] range instead of [0,1] transformer.set_channel_swap('data', (2,1,0)) # the reference model has channels in BGR order instead of RGB # set net to batch size of 50 net.blobs['data'].reshape(1,3,288,352) net.blobs['data'].data[...] = transformer.preprocess('data', caffe.io.load_image(image)) out = net.forward() #网络提取conv1的卷积核 #filters = net.params['conv1_1'][0].data # with open('FirstLayerFilter.pickle','wb') as f: # pickle.dump(filters,f) #vis_square(filters.transpose(0, 2, 3, 1)) #conv1的特征图 feat = net.blobs['pool3'].data[0, :256] with open('FirstLayerOutput.pickle','wb') as f: pickle.dump(feat,f) vis_square(feat,padval=1)# 此处将卷积图和进行显示,def vis_square(data, padsize=1, padval=0 ): plt.figure() data -= data.min() data /= data.max() #让合成图为方 n = int(np.ceil(np.sqrt(data.shape[0]))) padding = ((0, n ** 2 - data.shape[0]), (0, padsize), (0, padsize)) + ((0, 0),) * (data.ndim - 3) data = np.pad(data, padding, mode='constant', constant_values=(padval, padval)) #合并卷积图到一个图像中 data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1))) data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:]) print data.shape plt.imshow(data) plt.show()
net = initilize()testimage = '423.jpg'getNetDetails(testimage, net)prob = net.blobs['fc6'].data[0]print prob
阅读全文
0 0
- 使用python可视化特征层参数和特征图
- 逐层可视化图像特征
- caffe python接口:可视化每层图像特征
- 【Python】【Caffe】五、参数、特征图可视化《python调用caffe模块》
- Caffe 特征图可视化
- Caffe 特征图可视化
- win7 caffe使用笔记——特征图可视化(matlab,python两种方式)
- caffe cnn提取各层特征并可视化结果(Python接口)
- caffe预测、特征可视化python接口调用
- caffe预测、特征可视化python接口调用
- Caffe学习系列(17):模型各层特征和过滤器可视化
- Caffe学习系列(17):模型各层特征和过滤器可视化
- 【Cffe特征图可视化】【特征图】【非权重图】
- 【Caffe特征图可视化】【权重图weight】【特征图feat】
- caffe之特征图可视化及特征提取
- python 计算积分图和haar特征
- 学习笔记:深度学习网络特征逐层可视化
- Caffe提取任意层特征并进行可视化
- 【bzoj5106: [CodePlus2017]汀博尔】二分查找
- DBCA建库找不到ASM磁盘一例
- 丢人了!英伟达抄代码也就算了,竟然把人家的License都改成自己的
- JAVA 时间戳+随机数生成唯一ID
- AI一分钟 | 2017AI人才报告出炉!招聘猛增6倍,均薪达38万;机器人苏菲娅又作妖,呼吁沙特给予妇女更多权利
- 使用python可视化特征层参数和特征图
- !检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问
- 使用Jenkins配置SpringBoot的自动化构建
- 【推荐系统】Factorization Machine
- C# 学习笔记1 基本语法
- php使用PDO的方式连接mysql
- 计算机作业五
- hibernate要用到的jar包
- 微信小程序数据请求方法wx.request