1 Star 0 Fork 0

小荷才露尖尖角/SENet

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cifar.py 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
Ryuichiro Hataya 提交于 2019-11-27 13:05 . Update cifar.py
import torch.nn.functional as F
from homura import optim, lr_scheduler, callbacks, reporters
from homura.trainers import SupervisedTrainer as Trainer
from homura.vision.data.loaders import cifar10_loaders
from senet.baseline import resnet20
from senet.se_resnet import se_resnet20
def main():
train_loader, test_loader = cifar10_loaders(args.batch_size)
if args.baseline:
model = resnet20()
else:
model = se_resnet20(num_classes=10, reduction=args.reduction)
optimizer = optim.SGD(lr=1e-1, momentum=0.9, weight_decay=1e-4)
scheduler = lr_scheduler.StepLR(80, 0.1)
tqdm_rep = reporters.TQDMReporter(range(args.epochs))
_callbacks = [tqdm_rep, callbacks.AccuracyCallback()]
with Trainer(model, optimizer, F.cross_entropy, scheduler=scheduler, callbacks=_callbacks) as trainer:
for _ in tqdm_rep:
trainer.train(train_loader)
trainer.test(test_loader)
if __name__ == '__main__':
import argparse
p = argparse.ArgumentParser()
p.add_argument("--epochs", type=int, default=200)
p.add_argument("--batch_size", type=int, default=64)
p.add_argument("--reduction", type=int, default=16)
p.add_argument("--baseline", action="store_true")
args = p.parse_args()
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Heconnor/SENet.git
git@gitee.com:Heconnor/SENet.git
Heconnor
SENet
SENet
master

搜索帮助