apps/train.py
def save_model(model, save_dir=None):
    '''method to save a the trained deep neural network model'''
    #  Save the checkpoint
    # model.class_to_idx = image_datasets.class_to_idx
    model_path = None
    if save_dir is None:
        model_path = 'trained_model.pth'
    else:
        model_path = f'{save_dir}/trained_model.pth'

    checkpoint = {
        # 'arch': 'vgg16',
        # 'input_size': 25088,
        # 'output_size': 102,
        # 'hidden_units': 4096,
        'model': model.to(torch.device('cpu')),
        'features': model.features,
        'classifier': model.classifier,
        # 'optimizer': optimizer.state_dict(),
        'state_dict': model.state_dict(),
        # 'idx_to_class': {val: key for key, val in image_datasets.class_to_idx.items()}
    }

    torch.save(checkpoint, model_path)
    return model_path
method to save a the trained deep neural network model
method to save a the trained deep neural network model
method to save a the trained deep neural network model
def save_model(model, save_dir=None):
    model_path = None
    if save_dir is None:
        model_path = 'trained_model.pth'
    else:
        model_path = f'{save_dir}/trained_model.pth'
    checkpoint = {
        'model': model.to(torch.device('cpu')),
        'features': model.features,
        'classifier': model.classifier,
        'state_dict': model.state_dict(),
    }
    torch.save(checkpoint, model_path)
    return model_path
def save_model ( model , save_dir = None ) : model_path = None if save_dir is None : model_path = 'trained_model.pth' else : model_path = f'{save_dir}/trained_model.pth' checkpoint = { 'model' : model . to ( torch . device ( 'cpu' ) ) , 'features' : model . features , 'classifier' : model . classifier , 'state_dict' : model . state_dict ( ) , } torch . save ( checkpoint , model_path ) return model_path
method to save a the trained deep neural network model
method to save a the trained deep neural network model
'''method to save a the trained deep neural network model''' #  Save the checkpoint # model.class_to_idx = image_datasets.class_to_idx # 'arch': 'vgg16', # 'input_size': 25088, # 'output_size': 102, # 'hidden_units': 4096, # 'optimizer': optimizer.state_dict(), # 'idx_to_class': {val: key for key, val in image_datasets.class_to_idx.items()}
model
save_dir