参考地址: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. CSS学习笔记(9)--详解CSS中:nth-child的用法

    详解CSS中:nth-child的用法 前端的哥们想必都接触过css中一个神奇的玩意,可以轻松选取你想要的标签并给与修改添加样式,是不是很给力,它就是“:nth-child”. 下面我将用几个典型的实 ...

  2. Desugar Scala(15) -- unapply和unapplySeq方法

    欢迎关注我的新博客地址:http://cuipengfei.me/ 实在想不到什么动词可以当做脱衣服来讲了,所以从现在开始这系列博文就叫做Desugar Scala了.除非哪天才思泉涌,又想到了新词: ...

  3. VisualStudio快捷键

    ctrl+k,c 注释选中行 ctrl+k,u 取消对选中行的注释 CTRL + SHIFT + B:生成解决方案 CTRL + F7 :生成编译 CTRL + O :打开文件 CTRL + SHIF ...

  4. 002杰信-陌生的maven-web项目整改成我们熟悉的Web架构;classpath的含义;ssm框架的整合;junit测试

    这篇博客的资源来源于创智播客,先在此申明.这篇博客的出发点是jk项目,传智的做法是Maven的web模板生成的,但是这样子的结构目录与我们熟知的Web项目的结构目录相差很大,所以要按照我们熟知的项目结 ...

  5. 第二百四十四节,Bootstrap下拉菜单和滚动监听插件

    Bootstrap下拉菜单和滚动监听插件 学习要点: 1.下拉菜单 2.滚动监听 本节课我们主要学习一下 Bootstrap 中的下拉菜单插件,这个插件在以组件的形式我们 已经学习过,那么现在来看看怎 ...

  6. 多媒体开发之分场图像和交错图像interlacing---一个破解版的迅雷云点播网站

    [-] 目录 编辑描述 编辑去交错方法 编辑去交错源自电影的影像 编辑去交错交错式影像 编辑单一场去交错intra-field deinterlacing 编辑场间去交错inter-field dei ...

  7. ThinkPHP项目笔记之RBAC(权限)补充篇

    这里,主要补充的是配置以及相关代码问题. <?php return array( //'配置项'=>'配置值' 'RBAC_SUPERADMIN' => 'admin',//超级管理 ...

  8. 自定义 httpHandler 配置

    开发 环境 vs2010.asp.net 4.0 时 写在<system.web>  ,<httpHandlers>节点下 部署 环境Windows server 2007 , ...

  9. Logstash zabbix 插件

    zabbix 监控 logstash 安装社区扩展包wget http://download.elasticsearch.org/logstash/logstash/logstash-contrib- ...

  10. C++之强制类型转换

     C++ Code  12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...