- PyTorch 教程
- PyTorch - 主页
- PyTorch - 简介
- PyTorch - 安装
- 神经网络的数学构建模块
- PyTorch - 神经网络基础
- 机器学习的通用工作流
- 机器学习与深度学习
- 实现第一个神经网络
- 神经网络到功能模块
- PyTorch - 术语
- PyTorch - 载入数据
- PyTorch - 线性回归
- PyTorch - 卷积神经网络
- PyTorch - 循环神经网络
- PyTorch - 数据集
- PyTorch - 卷积简介
- 从头开始训练一个卷积
- PyTorch - 卷积中的特征提取
- PyTorch - 卷积的可视化
- 卷积中的序列处理
- PyTorch - 词嵌入
- PyTorch - 递归神经网络
- PyTorch 有用资源
- PyTorch - 快速指南
- PyTorch - 有用资源
- PyTorch - 讨论
PyTorch - 卷积中的特征提取
卷积神经网络包括一个主要特征,提取。以下步骤用于实现卷积神经网络的特征提取。
步骤 1
导入相应的模型以使用“PyTorch”创建特征提取模型。
import torch import torch.nn as nn from torchvision import models
步骤 2
创建一个功能提取器类,可以根据需要随时调用。
class Feature_extractor(nn.module):
def forward(self, input):
self.feature = input.clone()
return input
new_net = nn.Sequential().cuda() # the new network
target_layers = [conv_1, conv_2, conv_4] # layers you want to extract`
i = 1
for layer in list(cnn):
if isinstance(layer,nn.Conv2d):
name = "conv_"+str(i)
art_net.add_module(name,layer)
if name in target_layers:
new_net.add_module("extractor_"+str(i),Feature_extractor())
i+=1
if isinstance(layer,nn.ReLU):
name = "relu_"+str(i)
new_net.add_module(name,layer)
if isinstance(layer,nn.MaxPool2d):
name = "pool_"+str(i)
new_net.add_module(name,layer)
new_net.forward(your_image)
print (new_net.extractor_3.feature)
广告