python Tensorflow 实现图像的卷积处理
2024-10-19 23:25:09
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()
最新文章
- css 图片的无缝滚动
- mysql 表被锁处理方案
- formValidator的一些验证实例
- 今天学习到的关于mysql数据库的linux命令
- msmms (一) sms与mms区别
- linux解压命令
- WAJUEJI which home strong!
- F# 可以把几个函数组合成新函数
- 5 Logistic回归(二)
- 如何使用Visual Studio 2013 开发PHP5.6项目
- 【一天一道LeetCode】#30. Substring with Concatenation of All Words
- Linux----------nfs服务器的搭建及常识
- 初识大数据(二. Hadoop是什么)
- mysql解除死锁状态
- 从零开始部署一个 Laravel 站点
- [CodeForces - 614B] B - Gena's Code
- AppStore企业账号打包发布APP流程详解
- bash 括号(小括号,双小括号,中括号,双中括号,大括号)
- Loitor_产品(一)
- day06作业