utility_functions.py
def load_model_checkpoint(model_path):

    ''' 
    Load a pre-trained deep learning model which was saved with function
    "save_model_checkpoint()".
    
    Parameters:
     model_path   - full path to the saved model including the filename with the saved 
                    model data
    
    Returns:
     model        - deep learning model saved under "model_path" with the function 
                    "save_model_checkpoint()"
     criterion    - loss function with which the loaded model was trained (also saved along
                    with the model with the function "save_model_checkpoint()"
    
    '''
    
    # Load checkpoint data, ,add all tensors onto the CPU, using a function
    # Source: https://pytorch.org/docs/master/generated/torch.load.html      
    checkpoint = torch.load(model_path, map_location=lambda storage, loc: storage)
    
    ## Rebuild the model
    
    # Get model architecture
    arch = checkpoint['model_arch']
    
    # Load pretrained model with spedified model architecture
    model = getattr(models, arch)(pretrained=True)
    
    # Save architecture name to model:
    model.arch = arch
    
    # Load image input size required by specified model architecture
    model.input_size = checkpoint['input_size']
    
    # Load classifier of the model
    resnet = return_resnet_models()
    
    if arch in resnet:
        
        model.fc = checkpoint['classifier']
    
    else:
        model.classifier = checkpoint['classifier']
    

    # Load the state dict in to the network
    model.load_state_dict(checkpoint['model_state_dict'])
    
    # Load mapping
    model.class_to_idx = checkpoint['mapping']
    
    # Load criterion
    criterion =  checkpoint['criterion']

    # Return model and criterion
    return model, criterion
 
    Load a pre-trained deep learning model which was saved with function
    "save_model_checkpoint()".
    
    Parameters:
     model_path   - full path to the saved model including the filename with the saved 
                    model data
    
    Returns:
     model        - deep learning model saved under "model_path" with the function 
                    "save_model_checkpoint()"
     criterion    - loss function with which the loaded model was trained (also saved along
                    with the model with the function "save_model_checkpoint()"
    
    
Load a pre-trained deep learning model which was saved with function
"save_model_checkpoint()".

model_path   - full path to the saved model including the filename with the saved
model data


Load a pre - trained deep learning model which was saved with function " save_model_checkpoint () " . model_path - full path to the saved model including the filename with the saved model data
def load_model_checkpoint(model_path):
    checkpoint = torch.load(model_path, map_location=lambda storage, loc: storage)
    arch = checkpoint['model_arch']
    model = getattr(models, arch)(pretrained=True)
    model.arch = arch
    model.input_size = checkpoint['input_size']
    resnet = return_resnet_models()
    if arch in resnet:
        model.fc = checkpoint['classifier']
    else:
        model.classifier = checkpoint['classifier']
    model.load_state_dict(checkpoint['model_state_dict'])
    model.class_to_idx = checkpoint['mapping']
    criterion =  checkpoint['criterion']
    return model, criterion
def load_model_checkpoint ( model_path ) : checkpoint = torch . load ( model_path , map_location = lambda storage , loc : storage ) arch = checkpoint [ 'model_arch' ] model = getattr ( models , arch ) ( pretrained = True ) model . arch = arch model . input_size = checkpoint [ 'input_size' ] resnet = return_resnet_models ( ) if arch in resnet : model . fc = checkpoint [ 'classifier' ] else : model . classifier = checkpoint [ 'classifier' ] model . load_state_dict ( checkpoint [ 'model_state_dict' ] ) model . class_to_idx = checkpoint [ 'mapping' ] criterion = checkpoint [ 'criterion' ] return model , criterion
Load a pre-trained deep learning model which was saved with function
"save_model_checkpoint()".
Load a pre - trained deep learning model which was saved with function " save_model_checkpoint () " .
''' 
    Load a pre-trained deep learning model which was saved with function
    "save_model_checkpoint()".
    
    Parameters:
     model_path   - full path to the saved model including the filename with the saved 
                    model data
    
    Returns:
     model        - deep learning model saved under "model_path" with the function 
                    "save_model_checkpoint()"
     criterion    - loss function with which the loaded model was trained (also saved along
                    with the model with the function "save_model_checkpoint()"
    
    ''' # Load checkpoint data, ,add all tensors onto the CPU, using a function # Source: https://pytorch.org/docs/master/generated/torch.load.html       ## Rebuild the model # Get model architecture # Load pretrained model with spedified model architecture # Save architecture name to model: # Load image input size required by specified model architecture # Load classifier of the model # Load the state dict in to the network # Load mapping # Load criterion # Return model and criterion
model_path