加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

tensorflow-图像边缘+卷积+池化

发布时间:2020-12-14 04:30:05 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Tue Oct 2 13:23:27 2018 @author: myhaspl @email:[email?protected] tf.nn.conv2d+tf.nn.maxpool """ import tensorflow as tf from PIL import Image import numpy as np g=tf.Graph() wi
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Tue Oct 2 13:23:27 2018 @author: myhaspl @email:[email?protected] tf.nn.conv2d+tf.nn.maxpool """ import tensorflow as tf from PIL import Image import numpy as np g=tf.Graph() with g.as_default(): def getImageData(fileNameList): imageData=[] for fn in fileNameList: testImage = Image.open(fn).convert(‘L‘) testImage.show() imageData.append(np.array(testImage)[:,:,None]) return np.array(imageData,dtype=np.float32) imageFn=("tractor.png",) imageData=getImageData(imageFn) testData=tf.constant(imageData) kernel=tf.constant(np.array( [ [[[0.]],[[1.]],[[0.]]],[[[1.]],[[-4.]],[[1.]]],[[[0.]],[[0.]]] ]),dtype=tf.float32)#3*3*1*1 convData=tf.nn.conv2d(testData,kernel,strides=[1,1,1],padding="SAME") poolData=tf.nn.max_pool(convData,ksize=[1,2,padding=‘VALID‘) y1=tf.cast(convData,dtype=tf.int32) y2=tf.cast(poolData,dtype=tf.int32) init_op = tf.global_variables_initializer() with tf.Session(graph=g) as sess: print testData.get_shape() print kernel.get_shape() resultData1=sess.run(y1)[0] resultData2=sess.run(y2)[0] resultData1=resultData1.reshape(resultData1.shape[0],resultData1.shape[1]) resulImage1=Image.fromarray(np.uint8(resultData1),mode=‘L‘) resulImage1.show() resultData2=resultData2.reshape(resultData2.shape[0],resultData2.shape[1]) resulImage2=Image.fromarray(255-np.uint8(resultData2),mode=‘L‘) resulImage2.show() print y1.get_shape()
中间那个图是卷积,右边那个图是池化,自己对比一下,就明白池化的威力是很大的~
图像的卷积神经网络的操作流程就是:
CNN->DNN
DNN类似于普通神经网络,但属于深度神经网络,而CNN则强调
下面的过程
卷积->池化->卷积-池化

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读