Open Glorainow opened 1 month ago
Hello, recently I am also doing research work related to crowd counting, this is the evaluate_crowd_no_overlap function part that I provided for reference
`@torch.no_grad() def evaluate_crowd_no_overlap(model, val_dl, device): model.to(device) model.eval()
maes = []
mses = []
counts_pred, counts_true = [], [] # Storage of projected and real numbers
img_id = [] # 创建储存图片id的列表
# Iterate through the validation dataset
for samples, targets in val_dl:
samples = samples.to(device)
outputs = model(samples)
# Assuming that the model output contains the predicted points and corresponding scores
outputs_points = outputs['pred_points'][0]
outputs_scores = torch.nn.functional.softmax(outputs['pred_logits'], -1)[:, :, 1][0]
# Getting a count of real targets
gt_cnt = targets[0]['point'].shape[0]
# Filtering prediction points based on score thresholds
threshold = 0.5
points = outputs_points[outputs_scores > threshold].detach().cpu().numpy().tolist()
predict_cnt = int((outputs_scores>threshold).sum())
# accumulate MAE, MSE
mae = abs(predict_cnt - gt_cnt)
mse = (predict_cnt - gt_cnt) * (predict_cnt - gt_cnt)
maes.append(float(mae))
mses.append(float(mse))
# Storage of projected and real numbers
counts_pred.append(predict_cnt)
counts_true.append(gt_cnt)
img_id.append(int(targets[0]['image_id']))
# calc MAE, MSE
mae = np.mean(maes)
mse = np.sqrt(np.mean(mses))
# save_counts_to_file_sorted(f"{mse_dir}/counting_person_{mae:.2f}.txt", img_id, counts_pred)
return mae, mse`
Hello, recently I am also doing research work related to crowd counting, this is the evaluate_crowd_no_overlap function part that I provided for reference
`@torch.no_grad() def evaluate_crowd_no_overlap(model, val_dl, device): model.to(device) model.eval() # Inference is performed on all images to compute the MAE maes = [] mses = [] counts_pred, counts_true = [], [] # Storage of projected and real numbers img_id = [] # 创建储存图片id的列表 # Iterate through the validation dataset for samples, targets in val_dl: samples = samples.to(device) outputs = model(samples)
# Assuming that the model output contains the predicted points and corresponding scores outputs_points = outputs['pred_points'][0] outputs_scores = torch.nn.functional.softmax(outputs['pred_logits'], -1)[:, :, 1][0] # Getting a count of real targets gt_cnt = targets[0]['point'].shape[0] # Filtering prediction points based on score thresholds threshold = 0.5 points = outputs_points[outputs_scores > threshold].detach().cpu().numpy().tolist() predict_cnt = int((outputs_scores>threshold).sum()) # accumulate MAE, MSE mae = abs(predict_cnt - gt_cnt) mse = (predict_cnt - gt_cnt) * (predict_cnt - gt_cnt) maes.append(float(mae)) mses.append(float(mse)) # Storage of projected and real numbers counts_pred.append(predict_cnt) counts_true.append(gt_cnt) img_id.append(int(targets[0]['image_id'])) # calc MAE, MSE mae = np.mean(maes) mse = np.sqrt(np.mean(mses)) # save_counts_to_file_sorted(f"{mse_dir}/counting_person_{mae:.2f}.txt", img_id, counts_pred) return mae, mse`
请问,你这部分代码能跑吗?结果如何?
请问大家,有人能跑通训练代码吗?可以交流一下吗?
The evaluate_crowd_no_overlap function is not implemented. When would this be completed? Look forward to try APGCC!