apps/train.py
def main():
    '''Building and training of a deep neural network model with all the option 
       provided. Trained model will be save in the provided save directory'''

    print(
        "**********************************************************\nBUILD AND TRAIN A DEEP NEURAL NETWORK TO CLASSIFY FLOWERS!\n***********************************************************\n"
    )

    print('Validating arguments...')
    args = parse_args()

    if(not os.path.isdir(args.data_dir)):
        raise Exception(
            '[ERROR] data_dir option: Data directory does not exist')

    if(args.save_dir is not None and not os.path.isdir(args.save_dir)):
        raise Exception(
            '[ERROR] save_dir option: Save directory provided does not exist')

    data_dir = os.listdir(args.data_dir)
    if (not set(data_dir).issubset({'test', 'train', 'valid'})):
        raise Exception('[ERROR] Missing test, train or valid sub-directories')

    if args.arch not in ('vgg16', 'alexnet', 'densenet121', None):
        raise Exception(
            '[ERROR] --arch option: Unsupported model. Supported: vgg16, alexnet, and densenet121.')

    if args.gpu and torch.cuda.is_available():
        device = torch.device("cuda")
        print('[LOG] GPU enabled')
    elif not args.gpu:
        device = torch.device("cpu")
    else:
        raise Exception("[ERROR]--gpu option:  GPU not found")

    # running the main training
    print('[LOG] All arguments valid!\n[LOG] Processing the datasets...')
    loaders = get_data(args.data_dir)
    print('[LOG] Datasets processed!\n[LOG] Building the deep neural network model...')
    model = build_model(args.arch, args.hidden_units)
    print('[LOG] Model built!\n[LOG] training the model...')
    trained_model = train_model(
        model,
        loaders['train'],
        loaders['valid'],
        args.learning_rate,
        args.epochs,
        device
    )
    print('[LOG] Model trained!\n[LOG] Testing model accuracy...')
    test_model(
        trained_model,
        loaders['test'],
        device
    )
    print('[LOG] Saving model...')
    model_path = save_model(trained_model, args.save_dir)
    print(
        f'[SUCCESS] All training complete!\n[LOG] Trained model saved as {model_path}.')
Building and training of a deep neural network model with all the option 
       provided. Trained model will be save in the provided save directory
Building and training of a deep neural network model with all the option
provided. Trained model will be save in the provided save directory
Building and training of a deep neural network model with all the option provided . Trained model will be save in the provided save directory
def main():
    print(
        "**********************************************************\nBUILD AND TRAIN A DEEP NEURAL NETWORK TO CLASSIFY FLOWERS!\n***********************************************************\n"
    )
    print('Validating arguments...')
    args = parse_args()
    if(not os.path.isdir(args.data_dir)):
        raise Exception(
            '[ERROR] data_dir option: Data directory does not exist')
    if(args.save_dir is not None and not os.path.isdir(args.save_dir)):
        raise Exception(
            '[ERROR] save_dir option: Save directory provided does not exist')
    data_dir = os.listdir(args.data_dir)
    if (not set(data_dir).issubset({'test', 'train', 'valid'})):
        raise Exception('[ERROR] Missing test, train or valid sub-directories')
    if args.arch not in ('vgg16', 'alexnet', 'densenet121', None):
        raise Exception(
            '[ERROR] --arch option: Unsupported model. Supported: vgg16, alexnet, and densenet121.')
    if args.gpu and torch.cuda.is_available():
        device = torch.device("cuda")
        print('[LOG] GPU enabled')
    elif not args.gpu:
        device = torch.device("cpu")
    else:
        raise Exception("[ERROR]--gpu option:  GPU not found")
    print('[LOG] All arguments valid!\n[LOG] Processing the datasets...')
    loaders = get_data(args.data_dir)
    print('[LOG] Datasets processed!\n[LOG] Building the deep neural network model...')
    model = build_model(args.arch, args.hidden_units)
    print('[LOG] Model built!\n[LOG] training the model...')
    trained_model = train_model(
        model,
        loaders['train'],
        loaders['valid'],
        args.learning_rate,
        args.epochs,
        device
    )
    print('[LOG] Model trained!\n[LOG] Testing model accuracy...')
    test_model(
        trained_model,
        loaders['test'],
        device
    )
    print('[LOG] Saving model...')
    model_path = save_model(trained_model, args.save_dir)
    print(
        f'[SUCCESS] All training complete!\n[LOG] Trained model saved as {model_path}.')
def main ( ) : print ( "**********************************************************\nBUILD AND TRAIN A DEEP NEURAL NETWORK TO CLASSIFY FLOWERS!\n***********************************************************\n" ) print ( 'Validating arguments...' ) args = parse_args ( ) if ( not os . path . isdir ( args . data_dir ) ) : raise Exception ( '[ERROR] data_dir option: Data directory does not exist' ) if ( args . save_dir is not None and not os . path . isdir ( args . save_dir ) ) : raise Exception ( '[ERROR] save_dir option: Save directory provided does not exist' ) data_dir = os . listdir ( args . data_dir ) if ( not set ( data_dir ) . issubset ( { 'test' , 'train' , 'valid' } ) ) : raise Exception ( '[ERROR] Missing test, train or valid sub-directories' ) if args . arch not in ( 'vgg16' , 'alexnet' , 'densenet121' , None ) : raise Exception ( '[ERROR] --arch option: Unsupported model. Supported: vgg16, alexnet, and densenet121.' ) if args . gpu and torch . cuda . is_available ( ) : device = torch . device ( "cuda" ) print ( '[LOG] GPU enabled' ) elif not args . gpu : device = torch . device ( "cpu" ) else : raise Exception ( "[ERROR]--gpu option:  GPU not found" ) print ( '[LOG] All arguments valid!\n[LOG] Processing the datasets...' ) loaders = get_data ( args . data_dir ) print ( '[LOG] Datasets processed!\n[LOG] Building the deep neural network model...' ) model = build_model ( args . arch , args . hidden_units ) print ( '[LOG] Model built!\n[LOG] training the model...' ) trained_model = train_model ( model , loaders [ 'train' ] , loaders [ 'valid' ] , args . learning_rate , args . epochs , device ) print ( '[LOG] Model trained!\n[LOG] Testing model accuracy...' ) test_model ( trained_model , loaders [ 'test' ] , device ) print ( '[LOG] Saving model...' ) model_path = save_model ( trained_model , args . save_dir ) print ( f'[SUCCESS] All training complete!\n[LOG] Trained model saved as {model_path}.' )
Building and training of a deep neural network model with all the option
provided.
Building and training of a deep neural network model with all the option provided .
'''Building and training of a deep neural network model with all the option 
       provided. Trained model will be save in the provided save directory''' # running the main training