LBH1024 / CAN

When Counting Meets HMER: Counting-Aware Network for Handwritten Mathematical Expression Recognition (ECCV’2022 Poster).
MIT License
364 stars 59 forks source link

推理单张图片 #9

Closed Note-Liu closed 2 years ago

Note-Liu commented 2 years ago

在inference.py中,希望能够推理单张图片,加载训练好的权重,进行推理, 但输出的prediction几乎都是空的,请教一下这种原因是什么 with torch.no_grad(): for line in tqdm(lines): name, *labels = line.split() name = name.split('.')[0] if name.endswith('jpg') else name input_labels = labels print("input_labels:",input_labels) labels = ' '.join(labels) img = images[name] img = torch.Tensor(255-img) / 255 img = img.unsqueeze(0).unsqueeze(0) img = img.to(device) a = time.time() input_labels = words.encode(input_labels) input_labels = torch.LongTensor(input_labels) input_labels = input_labels.unsqueeze(0).to(device)

    probs, _, mae, mse = model(img, input_labels, os.path.join(params['decoder']['net']))
    mae_sum += mae
    mse_sum += mse
    model_time += (time.time() - a)

    prediction = words.decode(probs)
    print("pre:",prediction)
LBH1024 commented 2 years ago

你好,可能需要先确定几点:

  1. 你的训练集、验证集、测试集分别是?
  2. 在训练过程中会在验证集上挑选最优模型,得到的模型精度是多少?
  3. 几乎为空是指?你可以打印probs进行查看。
  4. infer的逻辑是当预测出『eos』结束符时就停止预测并返回,是否是在第一步就预测出了『eos』?
Note-Liu commented 2 years ago

Got it .Thanks!