|
import sys |
|
import os |
|
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, train_model_data_augmentation, train_model_backdoor |
|
from utils.parse_args import parse_args |
|
from model import LeNet5 |
|
|
|
def main(): |
|
|
|
args = parse_args() |
|
|
|
|
|
model = LeNet5() |
|
|
|
if args.train_type == '0': |
|
|
|
trainloader, testloader = get_cifar10_dataloaders(batch_size=args.batch_size) |
|
|
|
train_model( |
|
model=model, |
|
trainloader=trainloader, |
|
testloader=testloader, |
|
epochs=args.epochs, |
|
lr=args.lr, |
|
device=f'cuda:{args.gpu}', |
|
save_dir='../model', |
|
model_name='lenet5', |
|
save_type='0' |
|
) |
|
elif args.train_type == '1': |
|
train_model_data_augmentation( |
|
model, |
|
epochs=args.epochs, |
|
lr=args.lr, |
|
device=f'cuda:{args.gpu}', |
|
save_dir='../model', |
|
model_name='lenet5', |
|
batch_size=args.batch_size, |
|
num_workers=args.num_workers |
|
) |
|
elif args.train_type == '2': |
|
train_model_backdoor( |
|
model, |
|
poison_ratio=args.poison_ratio, |
|
target_label=args.target_label, |
|
epochs=args.epochs, |
|
lr=args.lr, |
|
device=f'cuda:{args.gpu}', |
|
save_dir='../model', |
|
model_name='lenet5', |
|
batch_size=args.batch_size, |
|
num_workers=args.num_workers |
|
) |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|