如何使用 libtorch 实现 VGG16 网络?
参考地址:https://ethereon.github.io/netscope/#/preset/vgg-16
按照上面的图来写即可。
论文地址:https://arxiv.org/pdf/1409.1556.pdf
// Define a new Module.
struct Net : torch::nn::Module {
Net() {
conv1_1 = torch::nn::Conv2d(torch::nn::Conv2dOptions(3, 64, { 3,3 }).padding(1));
conv1_2 = torch::nn::Conv2d(torch::nn::Conv2dOptions(64, 64, { 3,3 }).padding(1));
conv2_1 = torch::nn::Conv2d(torch::nn::Conv2dOptions(64, 128, { 3,3 }).padding(1));
conv2_2 = torch::nn::Conv2d(torch::nn::Conv2dOptions(128, 128, { 3,3 }).padding(1));
conv3_1 = torch::nn::Conv2d(torch::nn::Conv2dOptions(128, 256, { 3,3 }).padding(1));
conv3_2 = torch::nn::Conv2d(torch::nn::Conv2dOptions(256, 256, { 3,3 }).padding(1));
conv3_3 = torch::nn::Conv2d(torch::nn::Conv2dOptions(256, 256, { 3,3 }).padding(1));
conv4_1 = torch::nn::Conv2d(torch::nn::Conv2dOptions(256, 512, { 3,3 }).padding(1));
conv4_2 = torch::nn::Conv2d(torch::nn::Conv2dOptions(512, 512, { 3,3 }).padding(1));
conv4_3 = torch::nn::Conv2d(torch::nn::Conv2dOptions(512, 512, { 3,3 }).padding(1));
conv5_1 = torch::nn::Conv2d(torch::nn::Conv2dOptions(512, 512, { 3,3 }).padding(1));
conv5_2 = torch::nn::Conv2d(torch::nn::Conv2dOptions(512, 512, { 3,3 }).padding(1));
conv5_3 = torch::nn::Conv2d(torch::nn::Conv2dOptions(512, 512, { 3,3 }).padding(1));
fc1 = torch::nn::Linear(512*7*7,4096);
fc2 = torch::nn::Linear(4096, 4096);
fc3 = torch::nn::Linear(4096, 1000);
}
// Implement the Net's algorithm.
torch::Tensor forward(torch::Tensor x) {
x = conv1_1->forward(x);
x = torch::relu(x);
x = conv1_2->forward(x);
x = torch::relu(x);
x = torch::max_pool2d(x, { 2,2 }, { 2,2 });
x = conv2_1->forward(x);
x = torch::relu(x);
x = conv2_2->forward(x);
x = torch::relu(x);
x = torch::max_pool2d(x, { 2,2 }, { 2,2 });
x = conv3_1->forward(x);
x = torch::relu(x);
x = conv3_2->forward(x);
x = torch::relu(x);
x = conv3_3->forward(x);
x = torch::relu(x);
x = torch::max_pool2d(x, { 2,2 }, { 2,2 });
x = conv4_1->forward(x);
x = torch::relu(x);
x = conv4_2->forward(x);
x = torch::relu(x);
x = conv4_3->forward(x);
x = torch::relu(x);
x = torch::max_pool2d(x, { 2,2 }, { 2,2 });
x = conv5_1->forward(x);
x = torch::relu(x);
x = conv5_2->forward(x);
x = torch::relu(x);
x = conv5_3->forward(x);
x = torch::relu(x);
x = torch::max_pool2d(x, { 2,2 }, { 2,2 });
x = x.view({ x.size(0), -1 });//512x7x7 = 25088
x = fc1->forward(x);
x = torch::relu(x);
x = torch::dropout(x, 0.5, is_training());
x = fc2->forward(x);
x = torch::relu(x);
x = torch::dropout(x, 0.5, is_training());
x = fc3->forward(x);
x = torch::log_softmax(x, 1);
return x;
}
// Use one of many "standard library" modules.
torch::nn::Conv2d conv1_1{ nullptr };
torch::nn::Conv2d conv1_2{ nullptr };
torch::nn::Conv2d conv2_1{ nullptr };
torch::nn::Conv2d conv2_2{ nullptr };
torch::nn::Conv2d conv3_1{ nullptr };
torch::nn::Conv2d conv3_2{ nullptr };
torch::nn::Conv2d conv3_3{ nullptr };
torch::nn::Conv2d conv4_1{ nullptr };
torch::nn::Conv2d conv4_2{ nullptr };
torch::nn::Conv2d conv4_3{ nullptr };
torch::nn::Conv2d conv5_1{ nullptr };
torch::nn::Conv2d conv5_2{ nullptr };
torch::nn::Conv2d conv5_3{ nullptr };
torch::nn::Linear fc1{ nullptr };
torch::nn::Linear fc2{ nullptr };
torch::nn::Linear fc3{ nullptr };
};
如何使用 libtorch 实现 VGG16 网络?的更多相关文章
- 如何使用 libtorch 实现 AlexNet 网络?
如何使用 libtorch 实现 AlexNet 网络? 按照图片上流程写即可.输入的图片大小必须 227x227 3 通道彩色图片 // Define a new Module. struct Ne ...
- 如何使用 libtorch 实现 LeNet 网络?
如何使用 libtorch 实现 LeNet 网络? LeNet 网络论文地址: http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf
- 深度学习——卷积神经网络 的经典网络(LeNet-5、AlexNet、ZFNet、VGG-16、GoogLeNet、ResNet)
一.CNN卷积神经网络的经典网络综述 下面图片参照博客:http://blog.csdn.net/cyh_24/article/details/51440344 二.LeNet-5网络 输入尺寸:32 ...
- 卷积神经网络的一些经典网络(Lenet,AlexNet,VGG16,ResNet)
LeNet – 5网络 网络结构为: 输入图像是:32x32x1的灰度图像 卷积核:5x5,stride=1 得到Conv1:28x28x6 池化层:2x2,stride=2 (池化之后再经过激活函数 ...
- 第十三节,卷积神经网络之经典网络LeNet-5、AlexNet、VGG-16、ResNet(三)(后面附有一些网络英文翻译文章链接)
一 实例探索 上一节我们介绍了卷积神经网络的基本构建,比如卷积层.池化层以及全连接层这些组件.事实上,过去几年计算机视觉研究中的大量研究都集中在如何把这些基本构件组合起来,形成有效的卷积神经网络.最直 ...
- 【深度学习系列】用PaddlePaddle和Tensorflow实现经典CNN网络Vgg
上周我们讲了经典CNN网络AlexNet对图像分类的效果,2014年,在AlexNet出来的两年后,牛津大学提出了Vgg网络,并在ILSVRC 2014中的classification项目的比赛中取得 ...
- 学习TensorFlow,调用预训练好的网络(Alex, VGG, ResNet etc)
视觉问题引入深度神经网络后,针对端对端的训练和预测网络,可以看是特征的表达和任务的决策问题(分类,回归等).当我们自己的训练数据量过小时,往往借助牛人已经预训练好的网络进行特征的提取,然后在后面加上自 ...
- 第二十四节,TensorFlow下slim库函数的使用以及使用VGG网络进行预训练、迁移学习(附代码)
在介绍这一节之前,需要你对slim模型库有一些基本了解,具体可以参考第二十二节,TensorFlow中的图片分类模型库slim的使用.数据集处理,这一节我们会详细介绍slim模型库下面的一些函数的使用 ...
- 【超分辨率】—(ESRGAN)增强型超分辨率生成对抗网络-解读与实现
一.文献解读 我们知道GAN 在图像修复时更容易得到符合视觉上效果更好的图像,今天要介绍的这篇文章——ESRGAN: Enhanced Super-Resolution Generative Adve ...
随机推荐
- 从乌云的错误漏洞分析看Mifare Classic安全
前言 12年2月初国内著名安全问题反馈平台-乌云发布了有关某公司员工卡的金额效验算法破解的安全问题.从整个漏洞分析来看,漏洞的提交者把员工卡的数据分析得非常仔细,以至很多刚刚接触或者未曾接触的都纷纷赞 ...
- JQuery.getJSON 没反应
Jquery是一个优秀的Javascrīpt框架,轻量级的js库,它兼容CSS3.jQuery使用户能更方便地处理HTML documents.events.实现动画效果,并且方便地为网站提供AJAX ...
- flume+kafka
这里演示在单机fulume环境下,kafka作为source ,chanel , sink时三种情况 下面的测试都是基于下面的基本的配置文件进行修改的 a1.sources = r1 a1.sinks ...
- PHP——动态随机数
取1-13随机数 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- Linux开机启动文件rc.local无法执行怎么办?
rc.local是Linux系统中的一个重要的开机启动文件,每次开机都要执行这个文件.但是有一些用户的Linux系统无法执行这个文件,并导致了一系列的问题.遇到这个问题我们应该怎么办呢? 在Linux ...
- Storm手写WordCount
建立一个maven项目,在pom.xml中进行如下配置: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...
- Java解析json(二):jackson
Java解析json(二):jackson 官方参考 Jackson Home Page:https://github.com/FasterXML/jackson Jackson Wiki:htt ...
- Gogs http和ssh地址显示localhost的问题
问题描述: 如下图所示HTTP和SSH地址显示的是localhost而不是对应的域名或地址. 解决方案: 按以下方法修改Gogs配置文件并重启服务器 域名问题 RUN_USER = git DOMAI ...
- C语言0长度数组(柔性数组)
0长度数组,又称为柔性数组(flexible array).通经常使用来实现变长数组.常见于TLV(type-length-value)的数据结构中. 在标准 C 和 C++ 中,不同意用 0 长度数 ...
- UESTC 1511(差分约束)
题目链接:http://acm.uestc.edu.cn/problem.php?pid=1511 思路:我们可以等到这样的5个关系式: k=1:dsit[a]-dist[b]>=0&& ...