transformer模型预测时怎么使用PaddlePredictor?
Created by: tianjie491
模型已经训练完成并保存为inference model,现在需要进行预测。 预测方法为: def prediction(predictor, predict_data_generator): for sample in predict_data_generator(): max_seq_len = sample[0].shape[1] src_word = fake_input(sample[0], PaddleDType.INT64) src_pos = fake_input(sample[1], PaddleDType.INT64) src_slf_attn_bias = fake_input(sample[2], PaddleDType.FLOAT32) trg_word = fake_input(sample[3], PaddleDType.INT64) init_score = fake_input(sample[4], PaddleDType.FLOAT32) init_idx = fake_input(sample[5], PaddleDType.INT32) trg_src_attn_bias = fake_input(sample[6], PaddleDType.FLOAT32) seq_ids, seq_scores = predictor.run([ src_word, src_pos, src_slf_attn_bias, trg_word, init_score, init_idx, trg_src_attn_bias]) return seq_ids, seq_scores def fake_input(ids, dtype): data = PaddleTensor() data.name = "data" data.shape = list(ids.shape) data.dtype = dtype data.data = PaddleBuf(ids.flatten().tolist()) return data 但是sample[3]和sample[4]为lod_tensor没办法用fake_input方法进行转换,那对于lod_tensor应该怎么办呢?