示例#1
0
def main(argv):
    # train model is required in every case
    train_model = create_model(mode='train')
    if FLAGS.mode is "train_mode" or FLAGS.mode is "valid_mode":
        val_model = create_model(mode='valid',
                                 train_model_scope=train_model.scope)
    elif FLAGS.mode is "feeding_mode":
        feeding_model = create_model(mode='feeding',
                                     train_model_scope=train_model.scope)

    initializer = Initializer()
    initializer.start_session()

    # ---- training ----- #
    if FLAGS.mode is "train_mode":
        """either create new directory or reuse old one"""
        if not FLAGS.pretrained_model:
            output_dir = create_session_dir(FLAGS.output_dir)
        else:
            output_dir = FLAGS.pretrained_model
            print('Reusing provided session directory:', output_dir)

        tf.logging.info(' --- ' + FLAGS.mode.capitalize() + ' --- ')
        write_metainfo(output_dir, train_model.model_name, FLAGS)
        train(output_dir, initializer, train_model, val_model)

    # ---- validation  ----- #
    if FLAGS.mode is "valid_mode":
        assert FLAGS.pretrained_model
        if FLAGS.dump_dir:
            output_dir = FLAGS.dump_dir
        else:
            output_dir = create_subfolder(output_dir, 'valid_run')
        print('Storing validation data in:', output_dir)

        tf.logging.info(' --- ' + FLAGS.mode.capitalize() + ' --- ')
        validate(output_dir, initializer, val_model)

    # ---- feeding  ----- #
    if FLAGS.mode is "feeding_mode":
        tf.logging.info(' --- ' + FLAGS.mode.capitalize() + ' --- ')
        """ scenario 1: feed input from a directory to create hidden representations of query  """
        hidden_repr = create_batch_and_feed(initializer, feeding_model)
        print("output of model has shape: " + str(np.shape(hidden_repr)))
        """ scenario 2: load the memory and query it with the hidden reps to get nearest neighbours  """
        # alternatively, run a validation with the 'memory_prep' VALID MODE (settings) and set memory path in settings
        assert FLAGS.memory_path
        memory_df = pd.read_pickle(FLAGS.memory_path)
        memory = Memory(
            memory_df,
            '/common/homes/students/rothfuss/Documents/example/base_dir')

        # choose e.g. first hidden representation
        query = hidden_repr[0]
        _, cos_distances, _, paths = memory.matching(query)
        print(cos_distances, paths)
示例#2
0
def main():
    subprocess.run(['clear'])
    global RUNNING
    RUNNING = True

    signal.signal(signal.SIGINT, stopHandler)
    signal.signal(signal.SIGTERM, stopHandler)

    Initializer().initProjectAlice()
    projectAlice = ProjectAlice(restartHandler=restart)
    try:
        while RUNNING:
            time.sleep(0.1)
    except KeyboardInterrupt:
        _logger.info('Interruption detected')
    finally:
        projectAlice.onStop()
        _logger.info('Project Alice stopped, see you soon!')
        if projectAlice.restart:
            time.sleep(3)
            sys.stdout.flush()
            try:
                # Close everything related to ProjectAlice, allows restart without component failing
                p = psutil.Process(os.getpid())
                for h in p.open_files() + p.connections():
                    os.close(h.fd)
            except Exception as e:
                _logger.error(f'Failed restarting ProjectAlice: {e}')

            python = sys.executable
            os.execl(python, python, *sys.argv)
示例#3
0
def main():
    subprocess.run(['clear'])
    global RUNNING
    RUNNING = True

    signal.signal(signal.SIGINT, stopHandler)
    signal.signal(signal.SIGTERM, stopHandler)

    Initializer().initProjectAlice()
    projectAlice = ProjectAlice(restartHandler=restart)
    try:
        while RUNNING:
            time.sleep(0.1)
    except KeyboardInterrupt:
        _logger.info(
            '[Project Alice]           Interruption detected, preparing shutdown'
        )

    finally:
        if projectAlice.isBooted:
            projectAlice.onStop()

    _logger.info('[Project Alice]           Shutdown completed, see you soon!')
    if projectAlice.restart:
        time.sleep(3)
        restart()
示例#4
0
def main():
    subprocess.run(['clear'])
    global RUNNING

    signal.signal(signal.SIGINT, stopHandler)
    signal.signal(signal.SIGTERM, stopHandler)

    Initializer().initProjectAlice()
    projectAlice = ProjectAlice()
    try:
        while RUNNING:
            time.sleep(0.1)
    except KeyboardInterrupt:
        pass
    finally:
        projectAlice.onStop()
        _logger.info('Project Alice stopped, see you soon!')
示例#5
0
def main():
	subprocess.run(['clear'])
	global RUNNING
	RUNNING = True

	signal.signal(signal.SIGINT, stopHandler)
	signal.signal(signal.SIGTERM, stopHandler)

	Initializer().initProjectAlice()
	projectAlice = ProjectAlice(restartHandler=restart)
	try:
		while RUNNING:
			time.sleep(0.1)
	except KeyboardInterrupt:
		_logger.info('Interruption detected')
	finally:
		projectAlice.onStop()
		_logger.info('Project Alice stopped, see you soon!')
		if projectAlice.restart:
			time.sleep(3)
			sys.stdout.flush()
			main()
from core.util.model import FileFormatting, BashFormatting

_logger = logging.getLogger('ProjectAlice')
_logger.setLevel(logging.INFO)

date = int(datetime.now().strftime('%Y%m%d'))
logsMountpoint = Path(Path(__file__).resolve().parent, 'var', 'logs')

logFileHandler = logging.FileHandler(filename=f'{logsMountpoint}/logs.log',
                                     mode='w')
rotatingHandler = logging.handlers.RotatingFileHandler(
    filename=f'{logsMountpoint}/{date}-logs.log',
    mode='a',
    maxBytes=100000,
    backupCount=20)
streamHandler = logging.StreamHandler()

logFileFormatter = FileFormatting.Formatter()
bashFormatter = BashFormatting.Formatter()
logFileHandler.setFormatter(logFileFormatter)
rotatingHandler.setFormatter(logFileFormatter)
streamHandler.setFormatter(bashFormatter)

_logger.addHandler(logFileHandler)
_logger.addHandler(rotatingHandler)
_logger.addHandler(streamHandler)

from core.Initializer import Initializer

Initializer().initProjectAlice()