def load_model(model_file): model_file = model_file if args.student_model == '3CNN': model = net_distill.Net_3CNN(int(args.num_classes), int(args.num_channels)) elif args.student_model == '5CNN': model = net_distill.Net_5CNN(int(args.num_classes), int(args.num_channels)) elif args.student_model == '7CNN': model = net_distill.Net_7CNN(int(args.num_classes), int(args.num_channels)) checkpoint = torch.load(model_file, map_location=lambda storage, loc: storage) state_dict = {str.replace(k,'module.',''): v for k,v in checkpoint['state_dict'].items()} model.load_state_dict(state_dict) model.eval() return model
def load_model(path, student_model, num_classes_extract_step, num_channels): model_file = path if student_model == '3CNN' model = net_distill.Net_3CNN(num_classes_extract_step, num_channels) elif student_model == '5CNN' model = net_distill.Net_5CNN(num_classes_extract_step, num_channels) elif student_model == '7CNN' model = net_distill.Net_7CNN(num_classes_extract_step, num_channels) checkpoint = torch.load(model_file, map_location=lambda storage, loc: storage) state_dict = {str.replace(k,'module.',''): v for k,v in checkpoint['state_dict'].items()} #model.load_state_dict(checkpoint['state_dict']) model.load_state_dict(state_dict) for i, (name, module) in enumerate(model._modules.items()): module = recursion_change_bn(model) model.eval() return model