加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
nn_linear.py 1010 Bytes
一键复制 编辑 原始数据 按行查看 历史
AlbertDarren 提交于 2022-05-12 11:01 . first commit
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
@Time : 2022/5/6 08:41
@Author : Albert Darren
@Contact : 2563491540@qq.com
@File : nn_linear.py
@Version : Version 1.0.0
@Description : TODO
@Created By : PyCharm
"""
from torchvision.datasets import CIFAR10
from torchvision import transforms
from torch.utils.data import DataLoader
from torch import reshape, flatten
import torch.nn as nn
test_dataset = CIFAR10(root="cifai10", train=False, transform=transforms.ToTensor(), download=True)
dataloader = DataLoader(dataset=test_dataset, batch_size=64, drop_last=True)
class MyNet(nn.Module):
def __init__(self):
super(MyNet, self).__init__()
self.linear1 = nn.Linear(196608, 10)
def forward(self, x):
return self.linear1(x)
my_net = MyNet()
for data in dataloader:
images, targets = data
print(images.shape)
# output = reshape(images, (1, 1, 1, -1))
output = flatten(images)
print(output.shape)
print(my_net(output).shape)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化