import torch


def load_checkpoint(filepath):
    """
    This function Loads the trained model.
    
    Parameters:
        filepath - the path were the model is saved.
        
    Returns:
        model - the pretrained model
    """
    
    # load checkpoint and rebuild the model
    print("Loading Pretrained Model:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::")
    checkpoint = torch.load(filepath)
    checkpoint.keys()

    model = checkpoint['model']
    print(f"Model of Type {model} Sucessfully Loaded::::::::::::::::::::::::::::::::::::::::::::::: \n")
    
    #Freeze pre-trained model parameters
    for param in model.parameters():
        param.requires_grad = False
    
   
    classifier =  checkpoint['classifier']
    model.classifier = classifier
    model.load_state_dict(checkpoint['state_dict']) 
    model.class_to_idx = checkpoint['class_to_idx']
    
    return model