189 8069 5689

PyTorch普通卷积和空洞卷积实例-创新互联

如下所示:

成都创新互联公司-专业网站定制、快速模板网站建设、高性价比嘉祥网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式嘉祥网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖嘉祥地区。费用合理售后完善,10多年实体公司更值得信赖。
import numpy as np
from torchvision.transforms import Compose, ToTensor
from torch import nn
import torch.nn.init as init
def transform():
  return Compose([
    ToTensor(),
    # Normalize((12,12,12),std = (1,1,1)),
  ])

arr = range(1,26)
arr = np.reshape(arr,[5,5])
arr = np.expand_dims(arr,2)
arr = arr.astype(np.float32)
# arr = arr.repeat(3,2)
print(arr.shape)
arr = transform()(arr)
arr = arr.unsqueeze(0)
print(arr)

conv1 = nn.Conv2d(1, 1, 3, stride=1, bias=False, dilation=1) # 普通卷积
conv2 = nn.Conv2d(1, 1, 3, stride=1, bias=False, dilation=2) # dilation就是空洞率,即间隔
init.constant_(conv1.weight, 1)
init.constant_(conv2.weight, 1)
out1 = conv1(arr)
out2 = conv2(arr)
print('standare conv:\n', out1.detach().numpy())
print('dilated conv:\n', out2.detach().numpy())

标题名称:PyTorch普通卷积和空洞卷积实例-创新互联
文章URL:http://cdxtjz.com/article/pecci.html

其他资讯