课程学习 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集合中的List超详细讲解

《Java集合中的List超详细讲解》本文详细介绍了Java集合框架中的List接口,包括其在集合中的位置、继承体系、常用操作和代码示例,以及不同实现类(如ArrayList、LinkedList和V... 目录一,List的继承体系二,List的常用操作及代码示例1,创建List实例2,增加元素3,访问元

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解

《如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别详解》:本文主要介绍如何通过海康威视设备网络SDK进行Java二次开发摄像头车牌识别的相关资料,描述了如何使用海康威视设备网络SD... 目录前言开发流程问题和解决方案dll库加载不到的问题老旧版本sdk不兼容的问题关键实现流程总结前言作为

Python itertools中accumulate函数用法及使用运用详细讲解

《Pythonitertools中accumulate函数用法及使用运用详细讲解》:本文主要介绍Python的itertools库中的accumulate函数,该函数可以计算累积和或通过指定函数... 目录1.1前言:1.2定义:1.3衍生用法:1.3Leetcode的实际运用:总结 1.1前言:本文将详

Java深度学习库DJL实现Python的NumPy方式

《Java深度学习库DJL实现Python的NumPy方式》本文介绍了DJL库的背景和基本功能,包括NDArray的创建、数学运算、数据获取和设置等,同时,还展示了如何使用NDArray进行数据预处理... 目录1 NDArray 的背景介绍1.1 架构2 JavaDJL使用2.1 安装DJL2.2 基本操

Redis的Zset类型及相关命令详细讲解

《Redis的Zset类型及相关命令详细讲解》:本文主要介绍Redis的Zset类型及相关命令的相关资料,有序集合Zset是一种Redis数据结构,它类似于集合Set,但每个元素都有一个关联的分数... 目录Zset简介ZADDZCARDZCOUNTZRANGEZREVRANGEZRANGEBYSCOREZ

Go中sync.Once源码的深度讲解

《Go中sync.Once源码的深度讲解》sync.Once是Go语言标准库中的一个同步原语,用于确保某个操作只执行一次,本文将从源码出发为大家详细介绍一下sync.Once的具体使用,x希望对大家有... 目录概念简单示例源码解读总结概念sync.Once是Go语言标准库中的一个同步原语,用于确保某个操

SSID究竟是什么? WiFi网络名称及工作方式解析

《SSID究竟是什么?WiFi网络名称及工作方式解析》SID可以看作是无线网络的名称,类似于有线网络中的网络名称或者路由器的名称,在无线网络中,设备通过SSID来识别和连接到特定的无线网络... 当提到 Wi-Fi 网络时,就避不开「SSID」这个术语。简单来说,SSID 就是 Wi-Fi 网络的名称。比如

Java实现任务管理器性能网络监控数据的方法详解

《Java实现任务管理器性能网络监控数据的方法详解》在现代操作系统中,任务管理器是一个非常重要的工具,用于监控和管理计算机的运行状态,包括CPU使用率、内存占用等,对于开发者和系统管理员来说,了解这些... 目录引言一、背景知识二、准备工作1. Maven依赖2. Gradle依赖三、代码实现四、代码详解五

HarmonyOS学习(七)——UI(五)常用布局总结

自适应布局 1.1、线性布局(LinearLayout) 通过线性容器Row和Column实现线性布局。Column容器内的子组件按照垂直方向排列,Row组件中的子组件按照水平方向排列。 属性说明space通过space参数设置主轴上子组件的间距,达到各子组件在排列上的等间距效果alignItems设置子组件在交叉轴上的对齐方式,且在各类尺寸屏幕上表现一致,其中交叉轴为垂直时,取值为Vert