Exemple #1
0
def main():
    
    args = get_arguments()
    print(args)
    np.random.seed(args.seed)


    dataset, train_img_feature, train_data = get_train_data(args)
    dataset, test_img_feature,  test_data, val_answers = get_test_data(args)

    train_X = [train_data[u'question'], train_img_feature]
    train_Y = np_utils.to_categorical(train_data[u'answers'], args.nb_classes)

    test_X = [test_data[u'question'], test_img_feature]
    test_Y = np_utils.to_categorical(val_answers, args.nb_classes)


    model_name = importlib.import_module("models."+args.model)
    model = model_name.model(args)
    model.compile(loss='categorical_crossentropy', optimizer=args.optimizer, metrics=['accuracy'])
    model.summary() # prints model layers with weights

    history = model.fit(train_X, train_Y, batch_size = args.batch_size, nb_epoch=args.nb_epoch, validation_data=(test_X, test_Y))

    return history.history
Exemple #2
0
def main():
	print(colored('Drone Faces Main', 'blue'))

	print(colored('Gather Arguments...', 'blue'))
	args = get_arguments()
	print_args( args )

	### Load a trained model and fly the drone ###
	if args.fly_tello:
		pass
		# fly( args )

	elif args.train_model:
		pass

	elif args.load_images:
		load_images( args )




	print(colored('Whole Program has finished gracefully.', 'blue'))
Exemple #3
0
def main():
    # Argument parsing
    args = argparse.ArgumentParser()
    args = get_arguments()
    args.device = torch.device('cuda', args.gpu_id)

    # dataset/transform setting
    if args.in_dataset in ['cifar10']:
        args.num_classes = 10
    elif args.in_dataset in ['cifar100']:
        args.num_classes = 100

    # Get Dataloader
    transform = get_transform(args)
    train_dataloader, test_dataloader = globals()[args.in_dataset](args,
                                                                   transform)

    # Get architecture
    net = get_architecture(args)

    # Get optimizer, scheduler
    optimizer, scheduler = get_optim_scheduler(args, net)

    CE_loss = nn.CrossEntropyLoss()
    path = './checkpoint/' + args.in_dataset + '/' + args.arch + '_trial_' + args.trial
    best_acc = 0
    for epoch in range(args.epoch):
        train(args, net, train_dataloader, optimizer, scheduler, CE_loss,
              epoch)
        acc = test(args, net, test_dataloader, optimizer, scheduler, CE_loss,
                   epoch)
        scheduler.step()
        if best_acc < acc:
            best_acc = acc
            if not os.path.isdir('checkpoint/' + args.in_dataset):
                os.makedirs('checkpoint/' + args.in_dataset)
            torch.save(net.state_dict(), path)
Exemple #4
0
        # log model
        mlflow.pytorch.log_model(model, "models")

def main(config):
    # Ser directories (or create if they don't exist)
    set_dirs(config)
    # Get data loader for imaging dataset.
    img_loader = Loader(config, dataset_name="NucleiDataset")
    # Get data loader for RNA dataset.
    rna_loader = Loader(config, dataset_name="RNADataset")
    # Start training and save model weights at the end
    train(config, [img_loader, rna_loader], save_weights=True)

if __name__ == "__main__":
    # Get parser / command line arguments
    args = get_arguments()
    # Get configuration file
    config = get_config(args)
    # Summarize config and arguments on the screen as a sanity check
    print_config_summary(config, args)
    # --If True, start of MLFlow for experiment tracking:
    if config["mlflow"]:
        # Experiment name
        mlflow.set_experiment(experiment_name=config["model_mode"]+"_"+str(args.experiment))
        # Start a new mlflow run
        with mlflow.start_run():
            # Run the main
            main(config)
    else:
        # Run the main
        main(config)
def main():
    args = get_arguments()
    env = get_environment()

    # Called from cli, directory is required in this mode
    if args.directory:

        # Ensure path exists before continuing
        if not os.path.isdir(args.directory):
            log.critical('Directory not found. Exiting. "{}"'.format(
                args.directory))
            sys.exit(1)

        # Script called from cli with recursive flag set, ignore all other flags if this is set
        if args.recursive:
            dirs_scanned = 0
            trailers_downloaded = 0
            trailers_not_found = 0
            trailers_previously_dl = 0
            log.info('Recursive mode enabled. Scanning "{}".'.format(
                args.directory))
            # Loop through each subdirectory
            for sub_dir in os.listdir(args.directory):
                path = os.path.join(args.directory, sub_dir)
                if os.path.isdir(path):
                    directory = Movie_Folder(path)
                    if directory.has_movie:
                        dirs_scanned += 1
                        if not directory.has_trailer:
                            log.info('No Local trailer found in "{}"'.format(
                                directory.directory))
                            if _download_trailer(directory):
                                trailers_downloaded += 1
                            else:
                                trailers_not_found += 1
                        else:
                            log.info('Trailer already exists. "{}"'.format(
                                directory.trailer_filename))
                            trailers_previously_dl += 1
                    else:
                        log.warning(
                            'Assuming this is not a movie folder. No movie file found in "{}"'
                            .format(directory.directory))
                    log.info(
                        '------------------------------------------------------'
                    )
            log.info('Done!! Enjoy your new trailers!')
            log.info('Total directories scanned = {}'.format(dirs_scanned))
            log.info(
                'Total trailers downloaded = {}'.format(trailers_downloaded))
            log.info(
                'Total trailers not found  = {}'.format(trailers_not_found))
            log.info('Trailers previously found = {}'.format(
                trailers_previously_dl))

        # Script called from cli without recursive flag set with directory only
        elif not args.year and not args.title:
            log.info('Single Directory mode enabled. Scanning "{}"'.format(
                args.directory))
            directory = Movie_Folder(args.directory)
            if directory.has_movie:
                if not directory.has_trailer:
                    log.info('No Local trailer found in "{}"'.format(
                        directory.directory))
                    _download_trailer(directory)
                    log.info(
                        '------------------------------------------------------'
                    )
                else:
                    log.info('Trailer already exists. "{}"'.format(
                        directory.trailer_filename))
                    log.info(
                        '------------------------------------------------------'
                    )
            else:
                log.info(
                    'Assuming this is not a movie folder. No movie file found in "{}"'
                    .format(directory.directory))
                log.info(
                    '------------------------------------------------------')

        # Called from cli with year and title set
        elif args.title and args.year:
            # Start processing single directory from radarr env variables
            log.info('Single directory mode initiated for "{} ({})"'.format(
                args.title, args.year))
            directory = Movie_Folder(args.directory)
            directory.set_title_year(args.title, args.year)
            if directory.has_movie:
                if not directory.has_trailer:
                    log.info('No Local trailer found in {}'.format(
                        directory.directory))
                    _download_trailer(directory)
                    log.info(
                        '------------------------------------------------------'
                    )
                else:
                    log.info('Trailer already exists. "{}"'.format(
                        directory.trailer_filename))
            else:
                log.info(
                    'Assuming this is not a movie folder. No movie file found in "{}"'
                    .format(directory.directory))

        # Called from cli with imdbid set
        elif args.imdbid:
            log.info('Single directory mode initiated for imdb "{}"'.format(
                args.imdbid))
            directory = Movie_Folder(args.directory)
            directory.imdb_id = args.imdbid
            if directory.has_movie:
                if not directory.has_trailer:
                    log.info('No Local trailer found in "{}"'.format(
                        directory.directory))
                    _download_trailer(directory)
                    log.info(
                        '------------------------------------------------------'
                    )
                else:
                    log.info('Trailer already exists. "{}"'.format(
                        directory.trailer_filename))
                    log.info(
                        '------------------------------------------------------'
                    )
            else:
                log.info(
                    'Assuming this is not a movie folder. No movie file found in "{}"'
                    .format(directory.directory))
                log.info(
                    '------------------------------------------------------')

        # Called from cli with tmdbid set
        elif args.tmdbid:
            log.info('Single directory mode initiated for tmdb "{}"'.format(
                args.tmdbid))
            directory = Movie_Folder(args.directory)
            directory.tmdb_id = args.tmdbid
            if directory.has_movie:
                if not directory.has_trailer:
                    log.info('No Local trailer found for "{}" in {}'.format(
                        directory.title, directory.year))
                    _download_trailer(directory)
                    log.info(
                        '------------------------------------------------------'
                    )
                else:
                    log.info('Trailer already exists. "{}"'.format(
                        directory.trailer_filename))
            else:
                log.info(
                    'Assuming this is not a movie folder. No movie file found in "{}"'
                    .format(directory.directory))

        # Not enough data was provided in arguments to process
        else:
            log.warning('Not enough info was provided. Exiting.')
            sys.exit(1)

    # Called from Radarr with environment variables set
    elif env['valid']:
        log.info('Single directory mode initiated from Radarr')

        # Ensure directory exists before continuing
        if not os.path.isdir(env['movie_dir']):
            log.warning('Directory not found. Exiting. "{}"'.format(
                env['movie_dir']))
            sys.exit(1)

        directory = Movie_Folder(env['movie_dir'],
                                 title=env['title'],
                                 year=env['year'],
                                 tmdb=env['tmdbid'],
                                 imdb=env['imdbid'])
        if directory.has_movie:
            if not directory.has_trailer:
                log.info('No Local trailer found in "{}"'.format(
                    directory.directory))
                _download_trailer(directory)
                log.info(
                    '------------------------------------------------------')
            else:
                log.info('Trailer already exists. "{}"'.format(
                    directory.trailer_filename))
                log.info(
                    '------------------------------------------------------')
        else:
            log.info('No movie file found in "{}"'.format(directory.directory))
            log.info('------------------------------------------------------')

    # Called without enough information to find appropriate trailer
    else:
        log.warning('Script called without enough valid information. Exiting')
Exemple #6
0
#!/usr/bin/env python3

import os
from utils.logger import Logger
from utils.config import Config
from utils.environment import Env
from utils.arguments import get_arguments

__appName__ = 'TrailerTech'
__author__ = 'JsAddiction'
__version__ = '0.1.0'
__description__ = 'Download Trailers for your movie library.'

CONFIG_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                           'settings.ini')
LOG_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)),
                        'TrailerTech.log')
env = Env()
args = get_arguments(__appName__, __description__, __version__)
config = Config(CONFIG_PATH)
logger = Logger(LOG_PATH,
                config.log_level,
                config.log_to_file,
                quiet=args.quiet)