def main(hparams, cluster=None, results_dict=None): """ Main training routine specific for this project :param hparams: :return: """ # init experiment log_dir = os.path.dirname(os.path.realpath(__file__)) exp = Experiment( name='test_tube_exp', debug=True, save_dir=log_dir, version=0, autosave=False, description='test demo' ) hparams.training_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/training' hparams.validation_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/validation' hparams.test_task_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/test_task' hparams.batch_size = 4 # set the hparams for the experiment exp.argparse(hparams) exp.save() # build model model = ContrastivePredictiveSystem(hparams) # callbacks early_stop = EarlyStopping( monitor=hparams.early_stop_metric, patience=hparams.early_stop_patience, verbose=True, mode=hparams.early_stop_mode ) model_save_path = '{}/{}/{}'.format(hparams.model_save_path, exp.name, exp.version) checkpoint = ModelCheckpoint( filepath=model_save_path, save_best_only=True, verbose=True, monitor=hparams.model_save_monitor_value, mode=hparams.model_save_monitor_mode ) # configure trainer trainer = Trainer( experiment=exp, checkpoint_callback=checkpoint, early_stop_callback=early_stop, # distributed_backend='dp', #gpus=[0], nb_sanity_val_steps=2 ) # train model trainer.fit(model)
def test_classification_task_remote(self): weights_path = '/home/idivinci3005/experiments/checkpoints/_ckpt_epoch_20.ckpt' tags_path = '/home/idivinci3005/experiments/logs/immersions_scalogram_resnet/version_7/meta_tags.csv' task_dataset_path = '/home/idivinci3005/data/immersions/small_test_task' cpc_system = ContrastivePredictiveSystem.load_from_metrics( weights_path, tags_path, on_gpu=False) cpc_system.hparams.batch_size = 4 task_system = ClassificationTaskModel(cpc_system, task_dataset_path) task_system.calculate_data() trainer = pl.Trainer() trainer.fit(task_system)
def test_preprocessing_noise(self): dataset = MaestroDataset('/Volumes/Elements/Datasets/maestro-v2.0.0', item_length=176400, sampling_rate=44100, mode='validation', max_file_count=20, shuffle_with_seed=123) parser = HyperOptArgumentParser(strategy='random_search', add_help=False) #parser = ArgumentParser() parser = ContrastivePredictiveSystem.add_model_specific_args( parser, root_dir='../') hparams = parser.parse_args() preprocessing = PreprocessingModule(hparams) pass
def load_model(self, weights_path, tags_path, model_shapes_path, ranges_path): if self.dev != 'cpu' and torch.cuda.is_available(): self.model = ContrastivePredictiveSystem.load_from_metrics(weights_path, tags_path) self.model.model = self.model.model.module self.model.preprocessing = self.model.preprocessing.module self.model.to(self.dev) else: self.model = ContrastivePredictiveSystem.load_from_metrics(weights_path, tags_path) self.model.model = self.model.model.module self.model.preprocessing = self.model.preprocessing.module self.model.cpu() self.model.freeze() self.model.eval() self.register = self.model.activation_register self.register.active = True print("prediction_model weight", self.model.model.prediction_model.weight) pprint.pprint(self.model) self.activation_normalization = ActivationNormalization(self.mean_statistics, self.std_statistics, var_epsilon=1e-1, norm_epsilon=1e-2) self.model_activation = ModelActivations(shapes_path=model_shapes_path, ignore_time_dimension=False, remove_results=True) with open(ranges_path, 'rb') as handle: self.activation_ranges = pickle.load(handle) self.high_freq_filter = torch.linspace(-1., 1., steps=self.model_activation.shapes['scalogram'][1]) self.high_freq_filter = torch.clamp(self.high_freq_filter, 0., 1.)[None, :, None] if self.dev != 'cpu' and torch.cuda.is_available(): self.activation_normalization.cuda() self.high_freq_filter = self.high_freq_filter.cuda() else: self.activation_normalization.cpu() self.high_freq_filter.cpu()
def main(hparams, cluster=None, results_dict=None): """ Main training routine specific for this project :param hparams: :return: """ # init experiment log_dir = os.path.dirname(os.path.realpath(__file__)) exp = Experiment(name='test_tube_exp', debug=True, save_dir=log_dir, version=0, autosave=False, description='test demo') hparams.training_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/training' hparams.validation_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/validation' hparams.test_task_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/test_task' hparams.dummy_datasets = False hparams.audio_noise = 3e-3 hparams.cqt_fmin = 40. hparams.cqt_bins_per_octave = 24 hparams.cqt_n_bins = 216 hparams.cqt_hop_length = 512 hparams.cqt_filter_scale = 0.43 hparams.enc_channels = (1, 8, 16, 32, 64, 128, 256, 512, 512) hparams.enc_kernel_1_w = (3, 3, 3, 3, 3, 3, 3, 3) hparams.enc_kernel_1_h = (3, 3, 3, 3, 3, 3, 3, 3) hparams.enc_kernel_2_w = (1, 3, 1, 3, 1, 3, 1, 3) hparams.enc_kernel_2_h = (25, 3, 25, 3, 25, 3, 4, 3) hparams.enc_padding_1 = (1, 1, 1, 1, 1, 1, 1, 1) hparams.enc_padding_2 = (0, 1, 0, 1, 0, 1, 0, 0) hparams.enc_stride_1 = (1, 1, 1, 1, 1, 1, 1, 1) hparams.enc_stride_2 = (1, 1, 1, 1, 1, 1, 1, 1) hparams.enc_pooling_1 = (2, 1, 1, 1, 2, 1, 1, 1) hparams.ar_kernel_sizes = (5, 4, 1, 3, 3, 1, 3, 1, 6) hparams.ar_self_attention = (False, False, False, False, False, False, False, False, False) hparams.batch_size = 4 hparams.learning_rate = 3e-4 hparams.warmup_steps = 1000 hparams.annealing_steps = 100000 hparams.score_over_all_timesteps = False hparams.visible_steps = 60 # set the hparams for the experiment exp.argparse(hparams) exp.save() # build model model = ContrastivePredictiveSystem(hparams) # callbacks early_stop = EarlyStopping(monitor=hparams.early_stop_metric, patience=hparams.early_stop_patience, verbose=True, mode=hparams.early_stop_mode) model_save_path = '{}/{}/{}'.format(hparams.model_save_path, exp.name, exp.version) checkpoint = ModelCheckpoint(filepath=model_save_path, save_best_only=True, verbose=True, monitor=hparams.model_save_monitor_value, mode=hparams.model_save_monitor_mode) # configure trainer trainer = Trainer( experiment=exp, checkpoint_callback=checkpoint, #early_stop_callback=early_stop, # distributed_backend='dp', #gpus=[0], nb_sanity_val_steps=2, gradient_clip=0.5) # train model trainer.fit(model)
# configure trainer trainer = Trainer( experiment=exp, checkpoint_callback=checkpoint, #early_stop_callback=early_stop, # distributed_backend='dp', #gpus=[0], nb_sanity_val_steps=2, gradient_clip=0.5) # train model trainer.fit(model) if __name__ == '__main__': # use default args given by lightning root_dir = os.path.split(os.path.dirname( sys.modules['__main__'].__file__))[0] parent_parser = HyperOptArgumentParser(strategy='random_search', add_help=False) add_default_args(parent_parser, root_dir) # allow model to overwrite or extend args parser = ContrastivePredictiveSystem.add_model_specific_args( parent_parser, root_dir) hyperparams = parser.parse_args() # train model main(hyperparams)
import torch import pickle from immersions.cpc_system import ContrastivePredictiveSystem from immersions.input_optimization.activation_utilities import ActivationStatistics weights_path = '/Volumes/Elements/Projekte/Immersions/checkpoints/immersions_scalogram_resnet/_ckpt_epoch_20.ckpt' tags_path = '/Volumes/Elements/Projekte/Immersions/logs/immersions_scalogram_resnet/version_7/meta_tags.csv' ranges_path = '/Users/vincentherrmann/Documents/Projekte/Immersions/immersions/immersions/misc/immersions_scalogram_resnet_ranges.p' training_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/training' validation_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/validation' model = ContrastivePredictiveSystem.load_from_metrics( weights_path, tags_path, on_gpu=torch.cuda.is_available()) model.freeze() model.eval() model.hparams.training_set_path = training_set_path model.hparams.validation_set_path = validation_set_path model.batch_size = 8 model.setup_datasets() register = model.activation_register item_length = model.preprocessing_receptive_field + 63 * 4096 with open(ranges_path, 'rb') as handle: activation_ranges = pickle.load(handle) activation_statistics = ActivationStatistics() dataloader = model.tng_dataloader
def main(hparams, cluster=None, results_dict=None): """ Main training routine specific for this project :param hparams: :return: """ name = 'immersions_scalogram_resnet_house_smaller' version = 1 hparams.log_dir = '/home/idivinci3005/experiments/logs' hparams.checkpoint_dir = '/home/idivinci3005/experiments/checkpoints/' + name + '/' + str( version) hparams.training_set_path = '/home/idivinci3005/data/immersions/training' hparams.validation_set_path = '/home/idivinci3005/data/immersions/validation' hparams.test_task_set_path = '/home/idivinci3005/data/immersions/test_task' hparams.dummy_datasets = False hparams.audio_noise = 3e-3 hparams.cqt_fmin = 40. hparams.cqt_bins_per_octave = 24 hparams.cqt_n_bins = 216 hparams.cqt_hop_length = 512 hparams.cqt_filter_scale = 0.43 hparams.enc_channels = (1, 8, 16, 32, 64, 128, 256, 512, 512) hparams.enc_kernel_1_w = (3, 3, 3, 3, 3, 3, 3, 3) hparams.enc_kernel_1_h = (3, 3, 3, 3, 3, 3, 3, 3) hparams.enc_kernel_2_w = (1, 3, 1, 3, 1, 3, 1, 3) hparams.enc_kernel_2_h = (25, 3, 25, 3, 25, 3, 4, 3) hparams.enc_padding_1 = (1, 1, 1, 1, 1, 1, 1, 1) hparams.enc_padding_2 = (0, 1, 0, 1, 0, 1, 0, 0) hparams.enc_stride_1 = (1, 1, 1, 1, 1, 1, 1, 1) hparams.enc_stride_2 = (1, 1, 1, 1, 1, 1, 1, 1) hparams.enc_pooling_1 = (2, 1, 1, 1, 2, 1, 1, 1) hparams.ar_kernel_sizes = (5, 4, 1, 3, 3, 1, 3, 1, 6) hparams.ar_self_attention = (False, False, False, False, False, False, False, False, False) hparams.batch_size = 4 hparams.learning_rate = 3e-4 hparams.warmup_steps = 1000 hparams.annealing_steps = 100000 hparams.score_over_all_timesteps = False hparams.visible_steps = 60 hparams.batch_size = 32 hparams.learning_rate = 3e-4 hparams.warmup_steps = 1000 hparams.annealing_steps = 100000 hparams.score_over_all_timesteps = False hparams.visible_steps = 60 # init experiment exp = Experiment(name=name, debug=False, save_dir=hparams.log_dir, version=version, autosave=False, description='test demo') # set the hparams for the experiment exp.argparse(hparams) exp.save() # build model model = ContrastivePredictiveSystem(hparams) task_model = ClassificationTaskModel( model, task_dataset_path=hparams.test_task_set_path) # callbacks early_stop = EarlyStopping(monitor=hparams.early_stop_metric, patience=hparams.early_stop_patience, verbose=True, mode=hparams.early_stop_mode) checkpoint = ModelCheckpoint(filepath=hparams.checkpoint_dir, save_best_only=False, verbose=True, monitor=hparams.model_save_monitor_value, mode=hparams.model_save_monitor_mode) # configure trainer trainer = Trainer( experiment=exp, checkpoint_callback=checkpoint, #early_stop_callback=early_stop, #distributed_backend='dp', gpus=[0], nb_sanity_val_steps=5, val_check_interval=0.2, gradient_clip=0.5, track_grad_norm=2) # train model trainer.fit(model)
def main(hparams, cluster=None, results_dict=None): """ Main training routine specific for this project :param hparams: :return: """ name = 'immersions_scalogram_resnet_house' version = 0 hparams.log_dir = '/home/idivinci3005/experiments/logs' hparams.checkpoint_dir = '/home/idivinci3005/experiments/checkpoints/' + name + '/' + str( version) hparams.training_set_path = '/home/idivinci3005/data/immersions/training' hparams.validation_set_path = '/home/idivinci3005/data/immersions/validation' hparams.test_task_set_path = '/home/idivinci3005/data/immersions/test_task' hparams.dummy_datasets = False hparams.audio_noise = 3e-3 hparams.ar_kernel_sizes = (5, 4, 1, 3, 3, 1, 3, 1, 6) hparams.ar_self_attention = (False, False, False, False, False, False, False, False, False) hparams.batch_size = 32 hparams.learning_rate = 3e-4 hparams.warmup_steps = 1000 hparams.annealing_steps = 100000 hparams.score_over_all_timesteps = False hparams.visible_steps = 62 # init experiment exp = Experiment(name=name, debug=False, save_dir=hparams.log_dir, version=version, autosave=False, description='test demo') # set the hparams for the experiment exp.argparse(hparams) exp.save() # build model model = ContrastivePredictiveSystem(hparams) task_model = ClassificationTaskModel( model, task_dataset_path=hparams.test_task_set_path) # callbacks early_stop = EarlyStopping(monitor=hparams.early_stop_metric, patience=hparams.early_stop_patience, verbose=True, mode=hparams.early_stop_mode) checkpoint = ModelCheckpoint(filepath=hparams.checkpoint_dir, save_best_only=False, verbose=True, monitor=hparams.model_save_monitor_value, mode=hparams.model_save_monitor_mode) # configure trainer trainer = Trainer( experiment=exp, checkpoint_callback=checkpoint, early_stop_callback=early_stop, #distributed_backend='dp', gpus=[0], nb_sanity_val_steps=5, val_check_interval=0.2) # train model trainer.fit(model)
def test_training(self): # use default args given by lightning root_dir = '/Volumes/Elements/Projekte/Immersions' parent_parser = HyperOptArgumentParser(strategy='random_search', add_help=False) add_default_args(parent_parser, root_dir) # allow model to overwrite or extend args parser = ContrastivePredictiveSystem.add_model_specific_args(parent_parser, root_dir) hparams = parser.parse_args() name = 'immersions_scalogram_resnet_test' version = 0 hparams.log_dir = '/Volumes/Elements/Projekte/Immersions/logs' hparams.checkpoint_dir = '/Volumes/Elements/Projekte/Immersions/checkpoints' hparams.training_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/training' hparams.validation_set_path = '/Volumes/Elements/Datasets/Immersions/house_data_mp3/validation' hparams.dummy_datasets = False hparams.batch_size = 64 hparams.learning_rate = 2e-4 hparams.warmup_steps = 1000 hparams.annealing_steps = 100000 # init experiment exp = Experiment( name=name, debug=False, save_dir=hparams.log_dir, version=version, autosave=False, description='test demo' ) # set the hparams for the experiment exp.argparse(hparams) exp.save() # build model model = ContrastivePredictiveSystem(hparams) # callbacks early_stop = EarlyStopping( monitor=hparams.early_stop_metric, patience=hparams.early_stop_patience, verbose=True, mode=hparams.early_stop_mode ) checkpoint = ModelCheckpoint( filepath=hparams.checkpoint_dir, save_best_only=False, verbose=True, monitor=hparams.model_save_monitor_value, mode=hparams.model_save_monitor_mode ) # configure trainer trainer = Trainer( experiment=exp, checkpoint_callback=checkpoint, # early_stop_callback=early_stop, # distributed_backend='dp', gpus=[0], nb_sanity_val_steps=5, val_check_interval=0.2, train_percent_check=0.01, max_nb_epochs=1 ) # train model trainer.fit(model)