推理单张图片
Note-Liu opened this issue · comments
在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)
你好,可能需要先确定几点:
- 你的训练集、验证集、测试集分别是?
- 在训练过程中会在验证集上挑选最优模型,得到的模型精度是多少?
- 几乎为空是指?你可以打印probs进行查看。
- infer的逻辑是当预测出『eos』结束符时就停止预测并返回,是否是在第一步就预测出了『eos』?
Got it .Thanks!