参考地址: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 网络?的更多相关文章

  1. 如何使用 libtorch 实现 AlexNet 网络?

    如何使用 libtorch 实现 AlexNet 网络? 按照图片上流程写即可.输入的图片大小必须 227x227 3 通道彩色图片 // Define a new Module. struct Ne ...

  2. 如何使用 libtorch 实现 LeNet 网络?

    如何使用 libtorch 实现 LeNet 网络? LeNet 网络论文地址: http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf

  3. 深度学习——卷积神经网络 的经典网络(LeNet-5、AlexNet、ZFNet、VGG-16、GoogLeNet、ResNet)

    一.CNN卷积神经网络的经典网络综述 下面图片参照博客:http://blog.csdn.net/cyh_24/article/details/51440344 二.LeNet-5网络 输入尺寸:32 ...

  4. 卷积神经网络的一些经典网络(Lenet,AlexNet,VGG16,ResNet)

    LeNet – 5网络 网络结构为: 输入图像是:32x32x1的灰度图像 卷积核:5x5,stride=1 得到Conv1:28x28x6 池化层:2x2,stride=2 (池化之后再经过激活函数 ...

  5. 第十三节,卷积神经网络之经典网络LeNet-5、AlexNet、VGG-16、ResNet(三)(后面附有一些网络英文翻译文章链接)

    一 实例探索 上一节我们介绍了卷积神经网络的基本构建,比如卷积层.池化层以及全连接层这些组件.事实上,过去几年计算机视觉研究中的大量研究都集中在如何把这些基本构件组合起来,形成有效的卷积神经网络.最直 ...

  6. 【深度学习系列】用PaddlePaddle和Tensorflow实现经典CNN网络Vgg

    上周我们讲了经典CNN网络AlexNet对图像分类的效果,2014年,在AlexNet出来的两年后,牛津大学提出了Vgg网络,并在ILSVRC 2014中的classification项目的比赛中取得 ...

  7. 学习TensorFlow,调用预训练好的网络(Alex, VGG, ResNet etc)

    视觉问题引入深度神经网络后,针对端对端的训练和预测网络,可以看是特征的表达和任务的决策问题(分类,回归等).当我们自己的训练数据量过小时,往往借助牛人已经预训练好的网络进行特征的提取,然后在后面加上自 ...

  8. 第二十四节,TensorFlow下slim库函数的使用以及使用VGG网络进行预训练、迁移学习(附代码)

    在介绍这一节之前,需要你对slim模型库有一些基本了解,具体可以参考第二十二节,TensorFlow中的图片分类模型库slim的使用.数据集处理,这一节我们会详细介绍slim模型库下面的一些函数的使用 ...

  9. 【超分辨率】—(ESRGAN)增强型超分辨率生成对抗网络-解读与实现

    一.文献解读 我们知道GAN 在图像修复时更容易得到符合视觉上效果更好的图像,今天要介绍的这篇文章——ESRGAN: Enhanced Super-Resolution Generative Adve ...

随机推荐

  1. python跳一跳辅助学习

    微信跳一跳辅助工具 准备工具 adb驱动 安卓手机 打开手机的调试模式 usb接好手机和电脑 PyCharm:全宇宙唯一一款专门用于Python开发IDE工具 实现原理: 获取手机的实时的截图 点击起 ...

  2. Git中保存用户名和密码

    每次操作都需要输入用户名和密码感觉很繁琐,解决方法,在本地的工程文件夹的.git下打开config文件添加: [credential]     helper = store 再输入一次用户名密码后就可 ...

  3. lua错误收集

    这里放一些我遇到的lua错误,希望大家分享一些错误给我,统一放在这里. 1.lua表的引用传值 上面的代码运行后会发现t2[2],t2[3]表里的内容也被删除了,实际上它们 与t2[1]表里的内容都是 ...

  4. VS中C#读取app.config数据库配置字符串的三种方法(转)

    关于VS2008或VS2005中数据库配置字符串的三种取法 VS2008建立Form程序时,如果添加数据源会在配置文件 app.config中自动写入连接字符串,这个字符串将会在你利用DataSet, ...

  5. chrome显示小于12号字体的方法

    我现在做一个支持英文的网站,但是字体要设置小于12号字体,我百度方法是-webkit-text-size-adjust:none;  但是谷歌为什么不支持啊,  有没有解决办法 让谷歌浏览器 支持小于 ...

  6. 10个 jQuery 小技巧

    10个 jQuery 小技巧 -----整理by: xiaoshuai 1. 返回顶部按钮 可以利用 animate 和 scrollTop 来实现返回顶部的动画,而不需要使用其他插件. // Bac ...

  7. thinkPHP隐藏url地址栏中的index.php方法

    http://localhost/workSpace/First/index.php/Home/Index/index隐藏上面url中的index.php方法如下: 第一步.删除apache配置文件( ...

  8. 大圣画廊v0.2(2015.7.17)

    0.2版本号加入的功能 以tag分类图片 美化.添加瀑布流效果 添加tag页和单张图片页 添加公布图片页 以下是具体解释. 每添加一个功能,都要从模型.模板,视图,路由四个方面一一改动. 模型:添加t ...

  9. 深入了解Java之虚拟机内存

    在讨论JVM内存区域分析之前,先来看一下Java程序详细运行的过程: -我们今天就来分析一下Java程序运行过程的-Runtime-Data-Area(运行时数据)-这一块" class=& ...

  10. leetcode difficulty and frequency distribution chart

    Here is a difficulty and frequency distribution chart for each problem (which I got from the Interne ...