Exemplo n.º 1
0
    path = '/search/speech/hubo/git/tf-code-acoustics/chain_source_7300/'
    conf_dict = { 'batch_size' :64,
            'skip_offset': 0,
            'skip_frame':3,
            'shuffle': False,
            'queue_cache':2,
            'io_thread_num':5}
    feat_trans_file = '../conf/final.feature_transform'
    feat_trans = FeatureTransform()
    feat_trans.LoadTransform(feat_trans_file)
    io_read = KaldiDataReadParallel()
    #io_read.Initialize(conf_dict, scp_file=path+'cegs.all.scp_0',
    io_read.Initialize(conf_dict, scp_file=path+'cegs.1.scp',
            feature_transform = feat_trans, criterion = 'chain')

    io_read.Reset(shuffle = False)

    def Gen():
        while True:
            inputs = io_read.GetInput()
            if inputs[0] is not None:
                indexs, in_labels, weights, statesinfo, num_states = inputs[3]
                yield(inputs[0],inputs[1],inputs[2],indexs, in_labels, weights, statesinfo, num_states)
            else:
                print("-----end io----")
                break


    #dataset = KaldiDataset(io_read)
    dataset = tf.data.Dataset.from_generator(Gen, output_types=(tf.float32,tf.float32,tf.int32,tf.int32,tf.int32,tf.float32,tf.int32,tf.int32),output_shapes=None,args=None)
    
Exemplo n.º 2
0
    feat_trans = FeatureTransform()
    feat_trans.LoadTransform(feat_trans_file)
    logging.basicConfig(filename='test.log')
    logging.getLogger().setLevel('INFO')
    io_read = KaldiDataReadParallel()
    io_read.Initialize(
        conf_dict,
        scp_file=path + 'cegs.1.scp',
        #io_read.Initialize(conf_dict, scp_file=path+'scp',
        #io_read.Initialize(conf_dict, scp_file=path+'cegs.all.scp_0',
        feature_transform=feat_trans,
        criterion='chain')

    batch_info = 2000
    start = time.time()
    io_read.Reset(shuffle=False)
    batch_num = 0
    model = CommonModel(nnet_conf)

    # Instantiate an optimizer.
    optimizer = tf.keras.optimizers.SGD(learning_rate=0.1)
    # Instantiate a loss function.
    #loss_fn = tf.keras.losses.SparseCategoricalCrossentropy()
    loss_fn = tf.nn.softmax_cross_entropy_with_logits
    den_fst = '../chain_source/den.fst'
    den_indexs, den_in_labels, den_weights, den_statesinfo, den_num_states, den_start_state, laststatesuperfinal = Fst2SparseMatrix(
        den_fst)
    #leaky_hmm_coefficient = 0.000001
    leaky_hmm_coefficient = 0.1
    l2_regularize = 0.00005
    xent_regularize = 0.0