Closed Note-Liu closed 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)
你好,可能需要先确定几点:
Got it .Thanks!
在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)