def write_feature_files(models, n_samples, feature_dir, lab_dir): # Constants that should not make any difference samp_period = 0.01 max_file_samples = 2000 fea_prefix = 'test' htk_time_const = 1e7 fea_type = htkmfc.USER model_names = [] for m in models: model_names.append(m.name) n_dims = models[0].means.shape[1] n_fea_files = int(math.ceil(n_samples / float(max_file_samples))) samples_estimated = 0 file_names = [] for counter in range(n_fea_files): fea_name = fea_prefix + str(counter) file_names.append(fea_name + '.fea') fea_file_name = os.path.join(feature_dir, fea_name + '.fea') lab_file_name = os.path.join(lab_dir, fea_name + '.lab') n_samples_to_generate = min(max_file_samples, n_samples - samples_estimated) samples, ind_vector = SailGMM.sample_gmms(models, n_samples_to_generate) samples_estimated += n_samples_to_generate htk_lab_writer = htklab.HTKlab_write(filename=lab_file_name, samp_period=round(samp_period * htk_time_const), labels=model_names) htk_lab_writer.write(ind_vector) htk_fea_writer = htkmfc.HTKFeat_write(filename=fea_file_name, sampPeriod=int(samp_period * htk_time_const), veclen=n_dims, paramKind=fea_type) htk_fea_writer.writeall(samples) return (file_names)
def write_feature_files(models, n_samples, feature_dir, lab_dir): # Constants that should not make any difference samp_period = 0.01 max_file_samples = 2000 fea_prefix = 'test' htk_time_const = 1e7 fea_type = htkmfc.USER model_names = [] for m in models: model_names.append(m.name) n_dims = models[0].means.shape[1] n_fea_files = int(math.ceil(n_samples / float(max_file_samples))) samples_estimated = 0 file_names=[] for counter in range(n_fea_files): fea_name = fea_prefix+str(counter) file_names.append(fea_name+'.fea') fea_file_name = os.path.join(feature_dir,fea_name+'.fea') lab_file_name = os.path.join(lab_dir,fea_name+'.lab') n_samples_to_generate = min(max_file_samples, n_samples-samples_estimated) samples, ind_vector = SailGMM.sample_gmms(models, n_samples_to_generate) samples_estimated += n_samples_to_generate htk_lab_writer = htklab.HTKlab_write(filename=lab_file_name, samp_period=round(samp_period*htk_time_const), labels=model_names) htk_lab_writer.write(ind_vector) htk_fea_writer = htkmfc.HTKFeat_write(filename=fea_file_name, sampPeriod=int(samp_period*htk_time_const), veclen=n_dims, paramKind=fea_type) htk_fea_writer.writeall(samples) return(file_names)
if not os.path.exists(working_dir): try: os.makedirs(working_dir) except: logging.exception("Cannot create working directory: {}".format(working_dir)) # create file handler which logs even debug messages fh = logging.FileHandler(os.path.join(working_dir,'experiment.log')) fh.setLevel(logging.DEBUG) # create console handler with a higher log level ch = logging.StreamHandler() ch.setLevel(logging.INFO) # create formatter and add it to the handlers formatter = logging.Formatter('%(levelname)s - %(message)s') fh.setFormatter(formatter) ch.setFormatter(formatter) # add the handlers to the logger logger.addHandler(fh) logger.addHandler(ch) if model_file != None and os.path.exists(model_file): mod_f = open(model_file,'r') model_definition_string = mod_f.read() models = SailGMM.gmm_list_from_string(model_definition_string) test_gmm_classification(models=models, n_samples=n_samples, working_dir=args.working_dir, apply_hlda=args.apply_hlda, hlda_nuisance_dims=args.hlda_nuisance_dims, do_not_generate_features=args.do_not_generate_features)
except: logging.exception( "Cannot create working directory: {}".format(working_dir)) # create file handler which logs even debug messages fh = logging.FileHandler(os.path.join(working_dir, 'experiment.log')) fh.setLevel(logging.DEBUG) # create console handler with a higher log level ch = logging.StreamHandler() ch.setLevel(logging.INFO) # create formatter and add it to the handlers formatter = logging.Formatter('%(levelname)s - %(message)s') fh.setFormatter(formatter) ch.setFormatter(formatter) # add the handlers to the logger logger.addHandler(fh) logger.addHandler(ch) if model_file != None and os.path.exists(model_file): mod_f = open(model_file, 'r') model_definition_string = mod_f.read() models = SailGMM.gmm_list_from_string(model_definition_string) test_gmm_classification( models=models, n_samples=n_samples, working_dir=args.working_dir, apply_hlda=args.apply_hlda, hlda_nuisance_dims=args.hlda_nuisance_dims, do_not_generate_features=args.do_not_generate_features)