def init_config(): parser = myexman.ExParser(file=os.path.basename(__file__)) parser.add_argument('--name', type=str, default='') parser.add_argument('--epochs', type=int, default=160) parser.add_argument('--wd', type=float) parser.add_argument('--lr_schedule', type=str, default='original') parser.add_argument('--network', type=str, default='vgg') parser.add_argument('--dataset', type=str, default='cifar10') parser.add_argument('--batch_size', type=int, default=128) parser.add_argument('--exception', type=int, nargs='*', default=[]) parser.add_argument('--ratio', type=float, default=0.9) parser.add_argument('--prune_last', type=bool, default=True) parser.add_argument('--run', type=str, default='') parser.add_argument('--pruning', type=str, default='grasp') parser.add_argument('--seed', type=int, default=0) # Grasp params parser.add_argument('--samples_per_class', type=int, default=10) args = parser.parse_args() return args
def main(): parser = myexman.ExParser(file=os.path.basename(__file__)) add_learner_params(parser) is_help = False if '--help' in sys.argv or '-h' in sys.argv: sys.argv.pop( sys.argv.index('--help' if '--help' in sys.argv else '-h')) is_help = True args, _ = parser.parse_known_args(log_params=False) models.REGISTERED_MODELS[args.problem].add_model_hparams(parser) if is_help: sys.argv.append('--help') args = parser.parse_args(namespace=args) if args.data == 'imagenet' and args.aug == False: raise Exception('ImageNet models should be eval with aug=True!') if args.seed != -1: random.seed(args.seed) torch.manual_seed(args.seed) cudnn.deterministic = True args.gpu = 0 ngpus = torch.cuda.device_count() args.number_of_processes = 1 if args.dist == 'ddp': # add additional argument to be able to retrieve # of processes from logs # and don't change initial arguments to reproduce the experiment args.number_of_processes = args.world_size * ngpus parser.update_params_file(args) args.world_size *= ngpus mp.spawn( main_worker, nprocs=ngpus, args=(ngpus, args), ) else: parser.update_params_file(args) main_worker(args.gpu, -1, args)
import utils import utils_data from torch import nn from torch.optim.lr_scheduler import ReduceLROnPlateau from models import ResNet_cifar100 from models import ResNet_cifar10 from models import ResNet_tinyimagenet from models import ODENet_cifar100 from models import ODENet_cifar10 from models import ODENet_tinyimagenet from logger import Logger from utils import AverageMeter parser = myexman.ExParser(file=os.path.basename(__file__)) parser.add_argument('--name', default='') # Architecture parser.add_argument('--time', type=eval, default=True) parser.add_argument('--odenet', type=eval, default=False) parser.add_argument('--n_blocks', type=int, default=2) parser.add_argument('--norm', type=eval, default=False) # Data parser.add_argument('--data', default='cifar100', type=str) parser.add_argument('--data_seed', default=30, type=int) parser.add_argument('--val_size', default=0.2, type=float) parser.add_argument('--train_bs', default=512, type=int) parser.add_argument('--test_bs', default=512, type=int) parser.add_argument('--augmentation', default=True, type=eval) # Integration parser.add_argument('--tol', type=float, default=1e-3)
(args.epochs - args.decrease_from) + 1, 1.) return max(0, lr) def predict(data, net): pred = [] l = [] for x, y in data: l.append(y.numpy()) x = x.to(device) p = F.log_softmax(net(x), dim=1) pred.append(p.data.cpu().numpy()) return np.concatenate(pred), np.concatenate(l) parser = myexman.ExParser(file=__file__) parser.add_argument('--data', default='cifar') parser.add_argument('--num_examples', default=None, type=int) parser.add_argument('--data_split_seed', default=42, type=int) parser.add_argument('--resume', default='') parser.add_argument('--lr', default=0.001, type=float, help='Initial learning rate') parser.add_argument('--gamma', default=0.5, type=float) parser.add_argument('--epochs', default=100, type=int, help='Number of epochs') parser.add_argument('--decrease_from', default=0, type=int) parser.add_argument('--bs', default=256, type=int, help='Batch size') parser.add_argument('--test_bs', default=500, type=int,