예제 #1
0
파일: lord.py 프로젝트: matech96/lord
def train_encoders(args):
	assets = AssetManager(args.base_dir)
	model_dir = assets.get_model_dir(args.model_name)
	tensorboard_dir = assets.get_tensorboard_dir(args.model_name)

	data = np.load(assets.get_preprocess_file_path(args.data_name))
	imgs, classes, contents, n_classes = data['imgs'], data['classes'], data['contents'], data['n_classes']
	imgs = imgs.astype(np.float32) / 255.0

	converter = Converter.load(model_dir, include_encoders=False)

	glo_backup_dir = os.path.join(model_dir, args.glo_dir)
	if not os.path.exists(glo_backup_dir):
		os.mkdir(glo_backup_dir)
		converter.save(glo_backup_dir)

	converter.train_encoders(
		imgs=imgs,
		classes=classes,

		batch_size=default_config['train_encoders']['batch_size'],
		n_epochs=default_config['train_encoders']['n_epochs'],

		model_dir=model_dir,
		tensorboard_dir=tensorboard_dir
	)

	converter.save(model_dir)
예제 #2
0
def train(args):
    assets = AssetManager(args.base_dir)
    if not args.retrain:
        model_dir = assets.recreate_model_dir(args.model_name)
        tensorboard_dir = assets.recreate_tensorboard_dir(args.model_name)
    else:
        model_dir = assets.get_model_dir(args.model_name)
        tensorboard_dir = assets.get_tensorboard_dir(args.model_name)
    data = np.load(assets.get_preprocess_file_path(args.data_name))
    imgs = data['imgs'].astype(np.float32) / 255.0

    config = dict(
        img_shape=imgs.shape[1:],
        n_imgs=imgs.shape[0],
        n_classes=data['n_classes'].item(),
    )

    config.update(base_config)

    lord = Lord(config)
    if args.retrain:
        lord.load(model_dir, latent=True, amortized=False)
    lord.config = config
    lord.train_latent(imgs=imgs,
                      classes=data['classes'],
                      model_dir=model_dir,
                      tensorboard_dir=tensorboard_dir,
                      retrain=args.retrain)

    lord.save(model_dir, latent=True, amortized=False)
예제 #3
0
def train_encoders(args):
	assets = AssetManager(args.base_dir)
	model_dir = assets.get_model_dir(args.model_name)
	tensorboard_dir = assets.get_tensorboard_dir(args.model_name)

	data = np.load(assets.get_preprocess_file_path(args.data_name))
	imgs = data['imgs'].astype(np.float32) / 255.0

	backup_dir = os.path.join(model_dir, 'latent')
	if not os.path.exists(backup_dir):
		lord = Lord.load(model_dir, include_encoders=False)

		os.mkdir(backup_dir)
		lord.save(backup_dir)

	else:
		lord = Lord.load(backup_dir, include_encoders=False)

	lord.train_encoders(
		imgs=imgs,
		classes=data['classes'],

		batch_size=default_config['train_encoders']['batch_size'],
		n_epochs=default_config['train_encoders']['n_epochs'],

		model_dir=model_dir,
		tensorboard_dir=tensorboard_dir
	)

	lord.save(model_dir)
예제 #4
0
def train_encoders(args):
    assets = AssetManager(args.base_dir)
    model_dir = assets.get_model_dir(args.model_name)
    tensorboard_dir = assets.get_tensorboard_dir(args.model_name)

    data = np.load(assets.get_preprocess_file_path(args.data_name))
    imgs = data['imgs'].astype(np.float32) / 255.0

    lord = Lord()
    lord.load(model_dir, latent=True, amortized=False)

    lord.train_amortized(imgs=imgs,
                         classes=data['classes'],
                         model_dir=model_dir,
                         tensorboard_dir=tensorboard_dir)

    lord.save(model_dir, latent=False, amortized=True)
예제 #5
0
def train_encoders(args):
	assets = AssetManager(args.base_dir)
	model_dir = assets.get_model_dir(args.model_name)
	tensorboard_dir = assets.get_tensorboard_dir(args.model_name)
	data = np.load(assets.get_preprocess_file_path(args.data_name))
	imgs = data['imgs'].astype(np.float32) / 255.0

	config = dict(
		img_shape=imgs.shape[1:],
		n_imgs=imgs.shape[0],
		n_classes=data['n_classes'].item(),
	)

	config.update(base_config)

	lord = Lord(config)

	lord.train_encoders(
		imgs=imgs,
		classes=data['classes'],

		model_dir=model_dir,
		tensorboard_dir=tensorboard_dir
	)