python Tensorflow 实现图像的卷积处理

1.convolution.py

import numpy as np
from sklearn.datasets import  load_sample_images
import tensorflow as tf
import matplotlib.pyplot as plt

dataset = np.array(load_sample_images().images, dtype=np.float32)
batch_size, height, width, channels = dataset.shape

print(batch_size, height, width, channels)

print(type(dataset))

filters_test = tf.placeholder(tf.float32, shape=(15, 15, channels, 2))



X = tf.placeholder(tf.float32, shape=(None, height, width, channels))

dataset = dataset/255

convolution = tf.nn.conv2d(X, filter=filters_test, strides=[1, 2, 2, 1], padding='SAME')

with tf.Session() as sess:
    out = {}
    filters = np.zeros(shape=(15, 15, channels, 2))
    for i in range(2):
        if i == 0:
            filters[7, :, :, 1] = 1
        elif i == 1:
            filters[:, 7, :, 1] = 1
        output = sess.run(convolution, feed_dict={X: dataset, filters_test: filters})

        print(output)
        out['output'+str(i)] = output

print(output)




plt.imshow(dataset[0])
plt.show()

for i in out:
    # print(out[i])
    # max_value = max(out[i][0].reshape(-1, 1))
    # print(max_value)
    # out[i] = out[i]/max_value

    plt.title(i)
    plt.imshow(255*out[i][0, :, :, 1], cmap='bone')
    plt.show()

 

转载于:https://www.cnblogs.com/CK85/p/10282721.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值