tf.nn.separable_conv2d  tf.nn.depthwise_conv2d 深度可分离卷积 源码

博客提供了两个优快云的博客链接,分别为https://blog.youkuaiyun.com/mao_xiao_feng/article/details/78002811和https://blog.youkuaiyun.com/mao_xiao_feng/article/details/78003476,但未提及链接内具体信息技术内容。
import random import matplotlib.pyplot as plt import numpy as np import pandas as pd import torch.nn as nn from torch.utils.data import Dataset import torch import torch.nn.functional as F import torchvision.transforms as transforms from torch import nn class DepthwiseConv(nn.Module): def __init__(self, inp, oup): super(DepthwiseConv, self).__init__() self.depth_conv = nn.Sequential( # dw nn.Conv2d(inp, inp, kernel_size=3, stride=1, padding=1, groups=inp, bias=False), nn.BatchNorm2d(inp), # pw nn.Conv2d(inp, oup, kernel_size=1, stride=1, padding=0, bias=False), nn.BatchNorm2d(oup) ) def forward(self, x): return self.depth_conv(x) class depthwise_separable_conv(nn.Module): def __init__(self, ch_in, ch_out): super(depthwise_separable_conv, self).__init__() self.ch_in = ch_in self.ch_out = ch_out self.depth_conv = nn.Conv2d(ch_in, ch_in, kernel_size=3, padding=1, groups=ch_in) self.point_conv = nn.Conv2d(ch_in, ch_out, kernel_size=1) def forward(self, x): x = self.depth_conv(x) x = self.point_conv(x) return x class EEGNet(nn.Module): def __init__(self): super(EEGNet, self).__init__() self.T = 500 self.conv1 = nn.Conv2d(22,48,(3,3),padding=0) self.batchnorm1 = nn.BatchNorm2d(48,False) self.Depth_conv = DepthwiseConv(inp=48,oup=22) self.pooling1 = nn.AvgPool2d(4,4) self.Separable_conv = depthwise_separable_conv(ch_in=22, ch_out=48) self.batchnorm2 = nn.BatchNorm2d(48,False) self.pooling2 = nn.AvgPool2d(2,2) self.fc1 = nn.Linear(576, 256) self.fc2 = nn.Linear(256,64) self.fc3 = nn.Linear(64,4) def forward(self, item): x = F.relu(self.conv1(item)) x = self.batchnorm1(x) x = F.relu(self.Depth_conv(x)) x = self.pooling1(x) x = F.relu(self.Separable_conv(x)) x = self.batchnorm2(x) x = self.pooling2(x) #flatten x = x.contiguous().view(x.size()[0],-1) #view函数:-1为计算后的自动填充值=batch_size,或x = x.contiguous().view(batch_size,x.size()[0]) x = F.relu(self.fc1(x)) x = F.dropout(x,0.25) x = F.relu(self.fc2(x)) x = F.dropout(x,0.5) x = F.softmax(self.fc3(x),dim=1) return x 发生异常: RuntimeError Given groups=1, weight of size [48, 22, 3, 3], expected input[32, 1, 22, 1000] to have 22 channels, but got 1 channels instead File "D:\BCIshuju\2a+b\CNN-training-testing-templates-for-processing-EEG-signals-main\EEGNet_Module.py", line 61, in forward x = F.relu(self.conv1(item)) File "D:\BCIshuju\2a+b\CNN-training-testing-templates-for-processing-EEG-signals-main\Main.py", line 274, in <module> output = model(data) RuntimeError: Given groups=1, weight of size [48, 22, 3, 3], expected input[32, 1, 22, 1000] to have 22 channels, but got 1 channels instead
最新发布
10-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值