utility_functions.py
def save_model_checkpoint(image_datasets, model, optimizer, criterion, in_arg):
    
    """
    Function which saves the model so it can be loaded later for making predictions.
     
    Parameters:
     arch - 
    Returns:
     model - 
     
    """
    
    # The parameters for PyTorch networks are stored in a model's state_dict
    #print("Our model: \n\n", model, '\n')
    #print("The state dict keys: \n\n", model.state_dict().keys())
    #print(optimizer.state_dict().keys())
    
    # Directory for saving checkpoint
    save_dir = in_arg.save_dir
    
    # Save model architecture (name for reload it):
    model.arch = in_arg.arch

    # Mapping info
    model.class_to_idx = image_datasets['train'].class_to_idx
    
    resnet = return_resnet_models()
    
    # Set checkpoint diczionary
    checkpoint = {'model_arch': model.arch,
                  'input_size': model.input_size,
                  'model_state_dict': model.state_dict(),
                  'mapping': model.class_to_idx,
                  'optimizer_state_dict': optimizer.state_dict(),
                  'criterion': criterion}
    
    # Distinguish btw. model which 'classifer' and fc 'layer':
    if model.arch in resnet:
        checkpoint.update( {'classifier' : model.fc} )
        
    else:
        checkpoint.update( {'classifier' : model.classifier} )


    torch.save(checkpoint, save_dir)

    Function which saves the model so it can be loaded later for making predictions.
     
    Parameters:
     arch - 
    Returns:
     model - 
     
    
Function which saves the model so it can be loaded later for making predictions.
Parameters:
arch
Returns:
model
Function which saves the model so it can be loaded later for making predictions . Parameters : arch Returns : model
def save_model_checkpoint(image_datasets, model, optimizer, criterion, in_arg):
    save_dir = in_arg.save_dir
    model.arch = in_arg.arch
    model.class_to_idx = image_datasets['train'].class_to_idx
    resnet = return_resnet_models()
    checkpoint = {'model_arch': model.arch,
                  'input_size': model.input_size,
                  'model_state_dict': model.state_dict(),
                  'mapping': model.class_to_idx,
                  'optimizer_state_dict': optimizer.state_dict(),
                  'criterion': criterion}
    if model.arch in resnet:
        checkpoint.update( {'classifier' : model.fc} )
    else:
        checkpoint.update( {'classifier' : model.classifier} )
    torch.save(checkpoint, save_dir)
def save_model_checkpoint ( image_datasets , model , optimizer , criterion , in_arg ) : save_dir = in_arg . save_dir model . arch = in_arg . arch model . class_to_idx = image_datasets [ 'train' ] . class_to_idx resnet = return_resnet_models ( ) checkpoint = { 'model_arch' : model . arch , 'input_size' : model . input_size , 'model_state_dict' : model . state_dict ( ) , 'mapping' : model . class_to_idx , 'optimizer_state_dict' : optimizer . state_dict ( ) , 'criterion' : criterion } if model . arch in resnet : checkpoint . update ( { 'classifier' : model . fc } ) else : checkpoint . update ( { 'classifier' : model . classifier } ) torch . save ( checkpoint , save_dir )
Function which saves the model so it can be loaded later for making predictions.
Function which saves the model so it can be loaded later for making predictions .
"""
    Function which saves the model so it can be loaded later for making predictions.
     
    Parameters:
     arch - 
    Returns:
     model - 
     
    """ # The parameters for PyTorch networks are stored in a model's state_dict #print("Our model: \n\n", model, '\n') #print("The state dict keys: \n\n", model.state_dict().keys()) #print(optimizer.state_dict().keys()) # Directory for saving checkpoint # Save model architecture (name for reload it): # Mapping info # Set checkpoint diczionary # Distinguish btw. model which 'classifer' and fc 'layer':
image_datasets
model
optimizer
criterion
in_arg