RRFRRF
add some cv models and update readme.md
bdbd148
raw
history blame
1.24 kB
import sys
import os
import argparse
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from utils.dataset_utils import get_cifar10_dataloaders
from utils.train_utils import train_model
from model import AlexNet
def parse_args():
parser = argparse.ArgumentParser(description='训练AlexNet模型')
parser.add_argument('--gpu', type=int, default=0, help='GPU设备编号 (0,1,2,3)')
parser.add_argument('--batch-size', type=int, default=128, help='批次大小')
parser.add_argument('--epochs', type=int, default=200, help='训练轮数')
parser.add_argument('--lr', type=float, default=0.1, help='学习率')
return parser.parse_args()
def main():
# 解析命令行参数
args = parse_args()
# 获取数据加载器
trainloader, testloader = get_cifar10_dataloaders(batch_size=args.batch_size)
# 创建模型
model = AlexNet()
# 训练模型
train_model(
model=model,
trainloader=trainloader,
testloader=testloader,
epochs=args.epochs,
lr=args.lr,
device=f'cuda:{args.gpu}',
save_dir='../model',
model_name='alexnet'
)
if __name__ == '__main__':
main()