课程学习 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

相关文章

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

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

Ilya-AI分享的他在OpenAI学习到的15个提示工程技巧

Ilya(不是本人,claude AI)在社交媒体上分享了他在OpenAI学习到的15个Prompt撰写技巧。 以下是详细的内容: 提示精确化:在编写提示时,力求表达清晰准确。清楚地阐述任务需求和概念定义至关重要。例:不用"分析文本",而用"判断这段话的情感倾向:积极、消极还是中性"。 快速迭代:善于快速连续调整提示。熟练的提示工程师能够灵活地进行多轮优化。例:从"总结文章"到"用

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

学习hash总结

2014/1/29/   最近刚开始学hash,名字很陌生,但是hash的思想却很熟悉,以前早就做过此类的题,但是不知道这就是hash思想而已,说白了hash就是一个映射,往往灵活利用数组的下标来实现算法,hash的作用:1、判重;2、统计次数;

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

零基础学习Redis(10) -- zset类型命令使用

zset是有序集合,内部除了存储元素外,还会存储一个score,存储在zset中的元素会按照score的大小升序排列,不同元素的score可以重复,score相同的元素会按照元素的字典序排列。 1. zset常用命令 1.1 zadd  zadd key [NX | XX] [GT | LT]   [CH] [INCR] score member [score member ...]

【机器学习】高斯过程的基本概念和应用领域以及在python中的实例

引言 高斯过程(Gaussian Process,简称GP)是一种概率模型,用于描述一组随机变量的联合概率分布,其中任何一个有限维度的子集都具有高斯分布 文章目录 引言一、高斯过程1.1 基本定义1.1.1 随机过程1.1.2 高斯分布 1.2 高斯过程的特性1.2.1 联合高斯性1.2.2 均值函数1.2.3 协方差函数(或核函数) 1.3 核函数1.4 高斯过程回归(Gauss

ASIO网络调试助手之一:简介

多年前,写过几篇《Boost.Asio C++网络编程》的学习文章,一直没机会实践。最近项目中用到了Asio,于是抽空写了个网络调试助手。 开发环境: Win10 Qt5.12.6 + Asio(standalone) + spdlog 支持协议: UDP + TCP Client + TCP Server 独立的Asio(http://www.think-async.com)只包含了头文件,不依

【学习笔记】 陈强-机器学习-Python-Ch15 人工神经网络(1)sklearn

系列文章目录 监督学习:参数方法 【学习笔记】 陈强-机器学习-Python-Ch4 线性回归 【学习笔记】 陈强-机器学习-Python-Ch5 逻辑回归 【课后题练习】 陈强-机器学习-Python-Ch5 逻辑回归(SAheart.csv) 【学习笔记】 陈强-机器学习-Python-Ch6 多项逻辑回归 【学习笔记 及 课后题练习】 陈强-机器学习-Python-Ch7 判别分析 【学

系统架构师考试学习笔记第三篇——架构设计高级知识(20)通信系统架构设计理论与实践

本章知识考点:         第20课时主要学习通信系统架构设计的理论和工作中的实践。根据新版考试大纲,本课时知识点会涉及案例分析题(25分),而在历年考试中,案例题对该部分内容的考查并不多,虽在综合知识选择题目中经常考查,但分值也不高。本课时内容侧重于对知识点的记忆和理解,按照以往的出题规律,通信系统架构设计基础知识点多来源于教材内的基础网络设备、网络架构和教材外最新时事热点技术。本课时知识