use_fast = cfg.use_fast if arguments.has_key('use_fast'): use_fast = string_2_bool(arguments['use_fast']) kaldiread = KaldiReadIn(in_scp_file) kaldiwrite = KaldiWriteOut(out_ark_file) log('> ... setting up the CNN convolution layers') input_shape_train = conv_configs[0]['input_shape'] input_shape_1 = (input_shape_train[1], input_shape_train[2], input_shape_train[3]) rng = numpy.random.RandomState(123) theano_rng = RandomStreams(rng.randint(2 ** 30)) cnn = CNN_Forward(numpy_rng = rng, theano_rng=theano_rng, conv_layer_configs = conv_configs, use_fast = use_fast) _file2nnet(cnn.conv_layers, set_layer_num = len(conv_configs), filename=cnn_param_file) out_function = cnn.build_out_function() log('> ... processing the data') while True: uttid, in_matrix = kaldiread.read_next_utt() if uttid == '': break in_matrix = numpy.reshape(in_matrix, (in_matrix.shape[0],) + input_shape_1) out_matrix = out_function(in_matrix) kaldiwrite.write_kaldi_mat(uttid, out_matrix) kaldiwrite.close()
if arguments.has_key('use_fast'): use_fast = string2bool(arguments['use_fast']) kaldiread = KaldiReadIn(in_scp_file) kaldiwrite = KaldiWriteOut(out_ark_file) log('> ... setting up the CNN convolution layers') input_shape_train = conv_configs[0]['input_shape'] input_shape_1 = (input_shape_train[1], input_shape_train[2], input_shape_train[3]) rng = numpy.random.RandomState(123) theano_rng = RandomStreams(rng.randint(2**30)) cnn = CNN_Forward(numpy_rng=rng, theano_rng=theano_rng, conv_layer_configs=conv_configs, use_fast=use_fast) _file2nnet(cnn.conv_layers, set_layer_num=len(conv_configs), filename=cnn_param_file) out_function = cnn.build_out_function() log('> ... processing the data') while True: uttid, in_matrix = kaldiread.read_next_utt() if uttid == '': break in_matrix = numpy.reshape(in_matrix, (in_matrix.shape[0], ) + input_shape_1) out_matrix = out_function(in_matrix)
uttID, feat_mat = kaldiIn.next() if feat_mat == None: break kaldiIn.close() input_shape_train = conv_configs[0]['input_shape'] input_shape_1 = (input_shape_train[1], input_shape_train[2], input_shape_train[3]) num_utt = len(feat_mats_np) feat_mats = [] for i in xrange(num_utt): feat_mats.append(numpy.reshape(feat_mats_np[i], (feat_rows[i],) + input_shape_1)) rng = numpy.random.RandomState(123) theano_rng = RandomStreams(rng.randint(2 ** 30)) cnn = CNN_Forward(numpy_rng = rng, theano_rng=theano_rng, conv_layer_configs = conv_configs, use_fast = use_fast) _file2cnn(cnn.conv_layers, filename=conv_net_file) out_function = cnn.build_out_function(feat_mats) log('> ... processing the data') kaldiOut = KaldiWriteOut(output_scp,output_ark) kaldiOut.open() for i in xrange(num_utt): feat_out = out_function(feat_mats[i]) kaldiOut.write(uttIDs[i], feat_out) kaldiOut.close() end_time = time.clock() print >> sys.stderr, ('The code for file ' + os.path.split(__file__)[1] +