def load(self, folder): if os.path.isdir(folder): for root, dirs, files in os.walk(folder): for file in filter(lambda f: f.endswith(".wav"), files): self.logger.info( "Loading song %s and computing stft for it.", os.path.join(root, file)) song_type = os.path.splitext(file)[0].lower() if song_type == "mixture" or song_type == "vocals": song = Song(self.logger, os.path.basename(root), self.config) song.load_file(os.path.join(root, file)) song.compute_stft() if (song_type == "mixture"): self.mixtures.append(song) elif (song_type == "vocals"): self.vocals.append(song) self.logger.debug("%s loaded successfully.", song_type) else: self.logger.debug( "File %s is not named correctly. Ignoring...", song_type) else: self.logger.critical("Folder %s does not exist!", folder) sys.exit(8) if (len(self.mixtures) != len(self.vocals)): self.logger.critical( "There doesn't appear to be a vocal track for each mixture (or the other way around)." ) sys.exit(15)
validation_set.get_labels_for_cnn() model = Model(logging, config, dataset, validation_set) model.build(output_summary=True) if os.path.isfile(args.weights): logging.info("Found existing weights, loading them...") model.load(args.weights) model.train(args.epochs, save_log=config.getboolean("model", "save_history"), log_name=config.get("model", "history_filename")) logging.info("Saving weights...") model.save(args.weights) elif args.mode == "separate": logging.info("Preparing to separate vocals from instrumentals...") mixture = Song(logging, "a mixture", config) mixture.load_file(args.file) mixture.compute_stft(keep_spectrogram=True) dump_data = True if args.dump_data.lower() in ("yes", "true", "y", "t", "1") else False save_accompaniment = True if args.save_accompaniment.lower() in ( "yes", "true", "y", "t", "1") else False if dump_data is True: mixture.dump_amplitude("original") mixture.dump_spectrogram("original") model = Model(logging, config) model.build() if os.path.isfile(args.weights): model.load(args.weights) else: logging.critical("Couldn't find a weights file.") sys.exit(11) if dump_data is True: