Crowd Counting-Test 获取density map及counting number

1、get MAE and RMSE values

for i in range(0, len(img_paths)):
    img = transform(Image.open(img_paths[i]).convert('RGB')).cuda()
    img = img.unsqueeze(0)
    h,w = img.shape[2:4]
    h_d = int(h/2)
    w_d = int(w/2)
    img_1 = Variable(img[:,:,:h_d,:w_d].cuda())
    img_2 = Variable(img[:,:,:h_d,w_d:].cuda())
    img_3 = Variable(img[:,:,h_d:,:w_d].cuda())
    img_4 = Variable(img[:,:,h_d:,w_d:].cuda())
    density_1 = model(img_1).data.cpu().numpy()
    density_2 = model(img_2).data.cpu().numpy()
    density_3 = model(img_3).data.cpu().numpy()
    density_4 = model(img_4).data.cpu().numpy()

    pure_name = os.path.splitext(os.path.basename(img_paths[i]))[0]
    gt_file = h5py.File(img_paths[i].replace('.jpg', '.h5').replace('frame_', 'csvs_').replace('frames', 'csvs'), 'r')
    groundtruth = np.asarray(gt_file['density'])

    pred_sum = density_1.sum()+density_2.sum()+density_3.sum()+density_4.sum()
    pred.append(pred_sum)
    gt.append(np.sum(groundtruth))

mae = mean_absolute_error(pred,gt)
rmse = np.sqrt(mean_squared_error(pred,gt))

print('MAE: ', mae)
print('RMSE: ', rmse)

2、get density map

for i in range(0, 1):
    img = transform(Image.open(img_paths[i]).convert('RGB')).cuda()
    img = img.unsqueeze(0)
    img = Variable(img.cuda())

    density = model(img).data.cpu().numpy()
    plt.imshow(density[0][0], cmap=CM.jet)
    plt.show()

3、get counting number

        for i in range(0, len(imgs)):
            img = transform(Image.open(img_paths[i]).convert('RGB')).cuda()
            img = img.unsqueeze(0)
            img = Variable(img.cuda())
            density = model(img).data.cpu().numpy()

            pred_sum = density.sum()

            if pred_sum < 0.5:
                pred_sum = 0
            else:
                pred_sum = math.ceil(pred_sum)

            pred.append(pred_sum)
            sum = sum + pred_sum
            print(sum)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值