Exemplo n.º 1
0
    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()

    log('> ... the saved features are %s' % (out_ark_file))
Exemplo n.º 2
0
    theano_rng = RandomStreams(rng.randint(2**30))

    lstm = ATTEND_LSTM(numpy_rng=rng, theano_rng=theano_rng, cfg=cfg)
    _file2nnet(layers=lstm.layers,
               set_layer_num=len(lstm.layers),
               filename=lstm_param_file)
    out_function = lstm.build_extract_feat_function()

    while True:
        uttid, in_matrix = kaldiread.read_next_utt()
        if uttid == '':
            break
        print 'in_matrix:' + str(in_matrix.shape)
        final_matrix = numpy.zeros((in_matrix.shape[0], cfg.n_outs),
                                   dtype=theano.config.floatX)
        remainder = in_matrix.shape[0] % cfg.batch_size
        for index in xrange(in_matrix.shape[0] / cfg.batch_size):
            final_matrix[index * cfg.batch_size:(index + 1) *
                         cfg.batch_size] = out_function(
                             in_matrix[index * cfg.batch_size:(index + 1) *
                                       cfg.batch_size])
        if remainder > 0:
            print '\tremainder:' + str(remainder)
            final_matrix[-remainder:] = out_function(in_matrix[-remainder:])
        print 'final_matrix:' + str(final_matrix.shape)
        kaldiwrite.write_kaldi_mat(uttid, final_matrix)

    kaldiwrite.close()

    log('> ... the saved features are %s' % (out_ark_file))
Exemplo n.º 3
0
    rng = numpy.random.RandomState(89677)
    theano_rng = RandomStreams(rng.randint(2 ** 30))
    cfg.init_activation() 

    cnn = CNN_Forward(numpy_rng = rng, theano_rng=theano_rng, conv_layer_configs = conv_configs, use_fast = use_fast)
    #cnn = CNNV(numpy_rng = rng, theano_rng=theano_rng, cfg=cfg)
    _file2nnet(cnn.conv_layers, set_layer_num = len(conv_configs), filename=cnn_param_file)
    out_function = cnn.build_out_function()
    #out_function = cnn.build_extract_feat_function(-1)

    #print cnn.conv_layers[1].filter_shape
    model = DNNV(numpy_rng = rng, theano_rng = theano_rng, cfg = cfg, input=cnn.conv_layers[1].output)
    _file2nnet(model.layers, set_layer_num = len(model.layers)+len(conv_configs), start_layer=len(conv_configs), filename=cnn_param_file)

    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)
        extract_function = model.build_extract_feat_function(layer_index)
        mid_matrix = out_function(in_matrix)
        out_matrix = extract_function(mid_matrix)
        kaldiwrite.write_kaldi_mat(uttid, out_matrix)

    kaldiwrite.close()

    log('> ... the saved features are %s' % (out_ark_file))
Exemplo n.º 4
0
    kaldiread = KaldiReadIn(in_scp_file)
    kaldiwrite = KaldiWriteOut(out_ark_file)

    log('> ... setting up the ATTEND LSTM layers')
    rng = numpy.random.RandomState(89677)
    theano_rng = RandomStreams(rng.randint(2 ** 30))

    lstm = ATTEND_LSTM(numpy_rng=rng, theano_rng=theano_rng, cfg = cfg)
    _file2nnet(layers = lstm.layers, set_layer_num = len(lstm.layers), filename=lstm_param_file)
    out_function = lstm.build_extract_feat_function()

    while True:
        uttid, in_matrix = kaldiread.read_next_utt()
        if uttid == '':
            break
        print 'in_matrix:'+str(in_matrix.shape)
        final_matrix = numpy.zeros((in_matrix.shape[0],cfg.n_outs), dtype=theano.config.floatX)
        remainder = in_matrix.shape[0]%cfg.batch_size
        for index in xrange(in_matrix.shape[0]/cfg.batch_size):
            final_matrix[index*cfg.batch_size:(index+1)*cfg.batch_size] = out_function(in_matrix[index*cfg.batch_size:(index+1)*cfg.batch_size])
        if remainder > 0:
            print '\tremainder:'+str(remainder)
            final_matrix[-remainder:] = out_function(in_matrix[-remainder:])
        print 'final_matrix:'+str(final_matrix.shape)
        kaldiwrite.write_kaldi_mat(uttid, final_matrix)

    kaldiwrite.close()

    log('> ... the saved features are %s' % (out_ark_file))