课程学习 CV 北京邮电大学 鲁鹏(笔记四:CV经典网络讲解 之 VGG)

本文主要是介绍课程学习 CV 北京邮电大学 鲁鹏(笔记四:CV经典网络讲解 之 VGG),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

VGG

VGG论文:Very deep convolutional networks for large-scale image recognition
VGGNet由牛津大学的视觉几何组(Visual Geometry Group)提出,主要贡献在于证明了使用3x3的小卷积核,增加网络深度,可以有效提升模型性能,并且对于其他数据集也有很好的泛化性能。

VGG的结构简洁,整个网络都使用同样大小的卷积核尺寸(3x3)和最大池化尺寸(2x2)。到目前为止,VGG仍然被用来提取图像特征。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
定义卷积函数

def conv2d(x, W, b, strides=1):# Conv2D wrapper, with bias and relu activationx = tf.nn.conv2d(x, W, strides=[1, strides, strides, 1], padding='SAME')x = tf.nn.bias_add(x, b)return tf.nn.relu(x)

定义池化函数

def maxpool2d(x, k=2):# MaxPool2D wrapperreturn tf.nn.max_pool(x, ksize=[1, k, k, 1], strides=[1, k, k, 1], padding='SAME')

定义VGG结构

def conv_net(x, weights, biases, dropout):# Reshape input picture  x.shape:(128,128,3)x = tf.reshape(x, shape=[-1, 128, 128, 3])# Convolution Layerconv1 = conv2d(x, weights['wc1'], biases['bc1'])conv2 = conv2d(conv1, weights['wc2'], biases['bc2'])# Max Pooling (down-sampling)pool1 = maxpool2d(conv2, k=2)print(pool1.shape)  # (64,64,64)# Convolution Layerconv3 = conv2d(pool1, weights['wc3'], biases['bc3'])conv4 = conv2d(conv3, weights['wc4'], biases['bc4'])# Max Pooling (down-sampling)pool2 = maxpool2d(conv4, k=2)print(pool2.shape)  # (32,32,128)# Convolution Layerconv5 = conv2d(pool2, weights['wc5'], biases['bc5'])conv6 = conv2d(conv5, weights['wc6'], biases['bc6'])conv7 = conv2d(conv6, weights['wc7'], biases['bc7'])# Max Poolingpool3 = maxpool2d(conv7, k=2)print(pool3.shape)  # (16,16,256)# Convolution Layerconv8 = conv2d(pool3, weights['wc8'], biases['bc8'])conv9 = conv2d(conv8, weights['wc9'], biases['bc9'])conv10 = conv2d(conv9, weights['wc10'], biases['bc10'])# Max Poolingpool4 = maxpool2d(conv10, k=2)print(pool4.shape)  # (8,8,512)conv11 = conv2d(pool4, weights['wc11'], biases['bc11'])conv12 = conv2d(conv11, weights['wc12'], biases['bc12'])conv13 = conv2d(conv12, weights['wc13'], biases['bc13'])# Max Poolingpool5 = maxpool2d(conv13, k=2)print(pool5.shape)  # (4,4,512)# Fully connected layer# Reshape conv2 output to fit fully connected layer inputfc1 = tf.reshape(pool5, [-1, weights['wd1'].get_shape().as_list()[0]])fc1 = tf.add(tf.matmul(fc1, weights['wd1']), biases['bd1'])fc1 = tf.nn.relu(fc1)# Apply Dropoutfc1 = tf.nn.dropout(fc1, dropout)# fc2 = tf.reshape(fc1, [-1, weights['wd2'].get_shape().as_list()[0]])fc2 = tf.add(tf.matmul(fc1, weights['wd2']), biases['bd2'])fc2 = tf.nn.relu(fc2)# Apply Dropoutfc2 = tf.nn.dropout(fc2, dropout)'''fc3 = tf.reshape(fc2, [-1, weights['out'].get_shape().as_list()[0]])fc3 = tf.add(tf.matmul(fc2, weights['out']), biases['bd2'])fc3 = tf.nn.relu(fc2)'''# Output, class predictionout = tf.add(tf.matmul(fc2, weights['out']), biases['out'])return out

定义权重

weights = {# 3x3 conv, 3 input, 24 outputs'wc1': tf.Variable(tf.random_normal([3, 3, 3, 64])),'wc2': tf.Variable(tf.random_normal([3, 3, 64, 64])),'wc3': tf.Variable(tf.random_normal([3, 3, 64, 128])),'wc4': tf.Variable(tf.random_normal([3, 3, 128, 128])),'wc5': tf.Variable(tf.random_normal([3, 3, 128, 256])),'wc6': tf.Variable(tf.random_normal([3, 3, 256, 256])),'wc7': tf.Variable(tf.random_normal([3, 3, 256, 256])),'wc8': tf.Variable(tf.random_normal([3, 3, 256, 512])),'wc9': tf.Variable(tf.random_normal([3, 3, 512, 512])),'wc10': tf.Variable(tf.random_normal([3, 3, 512, 512])),'wc11': tf.Variable(tf.random_normal([3, 3, 512, 512])),'wc12': tf.Variable(tf.random_normal([3, 3, 512, 512])),'wc13': tf.Variable(tf.random_normal([3, 3, 512, 512])),# fully connected, 32*32*96 inputs, 1024 outputs'wd1': tf.Variable(tf.random_normal([4 * 4 * 512, 1024])),'wd2': tf.Variable(tf.random_normal([1024, 1024])),# 1024 inputs, 10 outputs (class prediction)'out': tf.Variable(tf.random_normal([1024, 10]))}

定义偏置

biases = {'bc1': tf.Variable(tf.random_normal([64])),'bc2': tf.Variable(tf.random_normal([64])),'bc3': tf.Variable(tf.random_normal([128])),'bc4': tf.Variable(tf.random_normal([128])),'bc5': tf.Variable(tf.random_normal([256])),'bc6': tf.Variable(tf.random_normal([256])),'bc7': tf.Variable(tf.random_normal([256])),'bc8': tf.Variable(tf.random_normal([512])),'bc9': tf.Variable(tf.random_normal([512])),'bc10': tf.Variable(tf.random_normal([512])),'bc11': tf.Variable(tf.random_normal([512])),'bc12': tf.Variable(tf.random_normal([512])),'bc13': tf.Variable(tf.random_normal([512])),'bd1': tf.Variable(tf.random_normal([1024])),'bd2': tf.Variable(tf.random_normal([1024])),'out': tf.Variable(tf.random_normal([10]))}

Construct model

pred = conv_net(x, weights, biases, keep_prob)# Define loss and optimizer损失and优化
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=pred, labels=y))
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)# Evaluate model
correct_pred = tf.equal(tf.argmax(pred, 1), tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))# Initializing the variables
init = tf.global_variables_initializer()
saver = tf.train.Saver()

VGG网络的大体结构就定义好了,只要初始化变量,设置Session,定义输入图像就可以跑了

这篇关于课程学习 CV 北京邮电大学 鲁鹏(笔记四:CV经典网络讲解 之 VGG)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/621198

相关文章

Java调用C++动态库超详细步骤讲解(附源码)

《Java调用C++动态库超详细步骤讲解(附源码)》C语言因其高效和接近硬件的特性,时常会被用在性能要求较高或者需要直接操作硬件的场合,:本文主要介绍Java调用C++动态库的相关资料,文中通过代... 目录一、直接调用C++库第一步:动态库生成(vs2017+qt5.12.10)第二步:Java调用C++

Python基础文件操作方法超详细讲解(详解版)

《Python基础文件操作方法超详细讲解(详解版)》文件就是操作系统为用户或应用程序提供的一个读写硬盘的虚拟单位,文件的核心操作就是读和写,:本文主要介绍Python基础文件操作方法超详细讲解的相... 目录一、文件操作1. 文件打开与关闭1.1 打开文件1.2 关闭文件2. 访问模式及说明二、文件读写1.

Linux系统配置NAT网络模式的详细步骤(附图文)

《Linux系统配置NAT网络模式的详细步骤(附图文)》本文详细指导如何在VMware环境下配置NAT网络模式,包括设置主机和虚拟机的IP地址、网关,以及针对Linux和Windows系统的具体步骤,... 目录一、配置NAT网络模式二、设置虚拟机交换机网关2.1 打开虚拟机2.2 管理员授权2.3 设置子

揭秘Python Socket网络编程的7种硬核用法

《揭秘PythonSocket网络编程的7种硬核用法》Socket不仅能做聊天室,还能干一大堆硬核操作,这篇文章就带大家看看Python网络编程的7种超实用玩法,感兴趣的小伙伴可以跟随小编一起... 目录1.端口扫描器:探测开放端口2.简易 HTTP 服务器:10 秒搭个网页3.局域网游戏:多人联机对战4.

C# WinForms存储过程操作数据库的实例讲解

《C#WinForms存储过程操作数据库的实例讲解》:本文主要介绍C#WinForms存储过程操作数据库的实例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、存储过程基础二、C# 调用流程1. 数据库连接配置2. 执行存储过程(增删改)3. 查询数据三、事务处

SpringBoot使用OkHttp完成高效网络请求详解

《SpringBoot使用OkHttp完成高效网络请求详解》OkHttp是一个高效的HTTP客户端,支持同步和异步请求,且具备自动处理cookie、缓存和连接池等高级功能,下面我们来看看SpringB... 目录一、OkHttp 简介二、在 Spring Boot 中集成 OkHttp三、封装 OkHttp

Linux系统之主机网络配置方式

《Linux系统之主机网络配置方式》:本文主要介绍Linux系统之主机网络配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、查看主机的网络参数1、查看主机名2、查看IP地址3、查看网关4、查看DNS二、配置网卡1、修改网卡配置文件2、nmcli工具【通用

使用Python高效获取网络数据的操作指南

《使用Python高效获取网络数据的操作指南》网络爬虫是一种自动化程序,用于访问和提取网站上的数据,Python是进行网络爬虫开发的理想语言,拥有丰富的库和工具,使得编写和维护爬虫变得简单高效,本文将... 目录网络爬虫的基本概念常用库介绍安装库Requests和BeautifulSoup爬虫开发发送请求解

C++快速排序超详细讲解

《C++快速排序超详细讲解》快速排序是一种高效的排序算法,通过分治法将数组划分为两部分,递归排序,直到整个数组有序,通过代码解析和示例,详细解释了快速排序的工作原理和实现过程,需要的朋友可以参考下... 目录一、快速排序原理二、快速排序标准代码三、代码解析四、使用while循环的快速排序1.代码代码1.由快

Java进阶学习之如何开启远程调式

《Java进阶学习之如何开启远程调式》Java开发中的远程调试是一项至关重要的技能,特别是在处理生产环境的问题或者协作开发时,:本文主要介绍Java进阶学习之如何开启远程调式的相关资料,需要的朋友... 目录概述Java远程调试的开启与底层原理开启Java远程调试底层原理JVM参数总结&nbsMbKKXJx