torch.nn.modules.module.ModuleAttributeError: 'Tudui' object has no attribute 'conv1'

利用dataset数据集进行卷积

import torchvision
from torch import nn
from torch.nn import Conv2d
from torch.utils.data import DataLoader

dataset_transform = torchvision.transforms.Compose([
torchvision.transforms.ToTensor()
])

获取数据集(标准数据集)

test_data = torchvision.datasets.CIFAR10(root=“PointCloud_data/data_3”, train=False,
transform=dataset_transform, download=True)

加载数据

test_loader = DataLoader(dataset=test_data, batch_size=4, shuffle=True, num_workers=0, drop_last=False)

搭载神经网络:对数据集进行操作

class Tudui(nn.Module):
def int(self):
super(Tudui, self).int()
self.conv1 = Conv2d(in_channels=3, out_channels=6, kernel_size=3, stride=1, padding=0)

def forward(self, _input):
    _output = self.conv1(_input)  # x输入到该卷积层
    return _output

声明类

tudui = Tudui()

for data in test_loader:
imgs, targets = data
output = tudui(imgs)
print(imgs.shape)

It seems you have a typo in the __init__ function and call it __int__.

Thank you for your reply