numpy构建卷积网络
import cv2
#读取一张图像
img = cv2.imread('1.jpg',cv2.IMREAD_GRAYSCALE)
def conv(img, conv_filter):if len(img.shape) > 2 or len(conv_filter.shape) > 3: # Check if number of image channels matches the filter depth.if img.shape[-1] != conv_filter.shape[-1]:print("Error: Number of channels in both image and filter must match.")sys.exit()if conv_filter.shape[1] != conv_filter.shape[2]: # Check if filter dimensions are equal.print('Error: Filter must be a square matrix. I.e. number of rows and columns must match.')sys.exit()```python#卷积核一般都把size设为奇数,主要有以下两个原因:#1.保证了锚点(卷积核的中心)刚好在中间,方便以模块中心为标准进行滑动卷积。#2.保证了padding时,图像的两边依然相对称。
if conv_filter.shape[1]%2==0: # Check if filter diemnsions are odd.print('Error: Filter must have an odd size. I.e. number of rows and columns must be odd.')sys.exit()# An empty feature map to hold the output of convolving the filter(s) with the image.feature_maps = numpy.zeros((img.shape[0]-conv_filter.shape[1]+1,img.shape[1]-conv_filter.shape[1]+1,conv_filter.shape[0]))# Convolving the image by the filter(s).for filter_num in range(conv_filter.shape[0]):print("Filter ", filter_num + 1)curr_filter = conv_filter[filter_num, :] # getting a filter from the bank.""" Checking if there are mutliple channels for the single filter. If so, then each channel will convolve the image.
. The result of all convolutions are summed to return a single feature map. """if len(curr_filter.shape) > 2:conv_map = conv_(img[:, :, 0], curr_filter[:, :, 0]) # Array holding the sum of all feature maps.for ch_num in range(1, curr_filter.shape[-1]): # Convolving each channel with the image and summing the results.conv_map = conv_map + conv_(img[:, :, ch_num],curr_filter[:, :, ch_num])else: # There is just a single channel in the filter.conv_map = conv_(img, curr_filter)feature_maps[:, :, filter_num] = conv_map # Holding feature map with the current filter.return feature_maps # Returning all feature maps.
numpy构建卷积网络相关推荐
- numpy 归一化_图卷积网络到底怎么做,这是一份极简的Numpy实现
由于图结构非常复杂且信息量很大,因此对于图的机器学习是一项艰巨的任务.本文介绍了如何使用图卷积网络(GCN)对图进行深度学习,GCN 是一种可直接作用于图并利用其结构信息的强大神经网络.本文将介绍 G ...
- 图卷积网络初探【GCN】
最近GCN非常火,虽然个人暂时用不到GCN,但还是简单看了下理论,感觉不是特别复杂,但是似乎实现上较为有难度,尤其是高维的图表示,先转载一篇机器之心的文章学习一下,感觉GCN主要是处理复杂的关系网络, ...
- 【Tensorflow】深度学习实战02——Tensorflow实现进阶的卷积网络(CIFAR-10)
[fishing-pan:https://blog.csdn.net/u013921430转载请注明出处] 前言 之前使用Tensorflow实现了一个简单卷积神经网络用于手写数字识别,那是一个简单的 ...
- TF之CNN:Tensorflow构建卷积神经网络CNN的简介、使用方法、应用之详细攻略
TF之CNN:Tensorflow构建卷积神经网络CNN的简介.使用方法.应用之详细攻略 目录 TensorFlow 中的卷积有关函数入门 1.tf.nn.conv2d函数 案例应用 1.TF之CNN ...
- (刘二大人)PyTorch深度学习实践-卷积网络(Advance)
1. 1x1的卷积核的作用 在width和height不变的基础上改变通道的数量 减少计算量 2. GoogLeNet中Inception Module的实现 2.1 Inception块的代码实现 ...
- 卷积网络和卷积神经网络_CNTK-卷积神经网络
卷积网络和卷积神经网络 CNTK-卷积神经网络 (CNTK - Convolutional Neural Network) In this chapter, let us study how to c ...
- LIVE 预告 | TransGAN:丢弃卷积,纯Transformer构建GAN网络
自2014年Ian J. Goodfellow等人提出以来,生成对抗网络(GAN,Generative Adversarial Networks)便迅速成为人工智能领域中最有前景的研究方向之一. 而另 ...
- keras构建卷积神经网络_通过此简单教程学习在网络上构建卷积神经网络
keras构建卷积神经网络 by John David Chibuk 约翰·大卫·奇布克(John David Chibuk) 通过此简单教程学习在网络上构建卷积神经网络 (Learn to buil ...
- 自动调试用于移动GPU的卷积网络
自动调试用于移动GPU的卷积网络 对特定设备进行自动调试对于获得最佳性能至关重要.这是有关如何调试整个卷积网络的说明文档. TVM中Mobile GPU的算子实现以模板形式编写.模板具有许多可调旋钮( ...
- ARM-CPU卷积网络的自动调谐
ARM-CPU卷积网络的自动调谐 为特定的ARM设备自动调谐对于获得最佳性能至关重要.这是一个关于如何调整整个卷积网络的资料. 以模板的形式编写了TVM中ARM CPU的操作实现.模板有许多可调旋钮( ...
最新文章
- PHP向第三方接口发送json数据
- 【C 语言】文件操作 ( 配置文件读写 | 框架搭建 | 头文件定义 | 头文件导入限制 | 兼容 C++ 语言 | 函数形参输入输出属性注释)
- 动态IP代理软件有话说:天下爬虫框架皆出Scrapy
- 以大多数人的努力程度之低,根本轮不到去拼天赋
- ASP.NET MVC Json的序列化和反序列化
- Angular元素属性绑定的一个例子
- [Python][小知识][NO.3] Python 使用系统默认浏览器打开指定URL的网址
- 开源目标检测算法用于交通标志检测全方位评估
- java键盘监听keyadapter_JAVA 键盘监听当中,释放键盘并没有停止运动
- 从 TDSQL 演进史,探索国产数据库发展规律
- 详解MySQL双活同步复制四种解决方案
- Request,Request.Form,Request.QueryString
- php使用地图插件,wordpress的百度地图插件怎么使用
- 橡胶柱压缩_橡胶=汽车半条命:浅谈ABAQUS橡胶大变形仿真5大注意事项
- 通过上位机软件测试总线舵机
- 基本输入输出系统BIOS
- js为li列表添加点击事件
- Python实现行业轮动量化选股【附完整源码】
- 【保姆级讲解】C语言---指针精华
- 人工智能:确定性推理