wskingdom/Crowd-Hat

The position of the bounding box drawn as a result of the image demo is strange.

Opened this issue · 0 comments

hello.
I am trying to run the Hat_LSC-CNN model and see the results.
https://huggingface.co/WSKINGDOM/lsc_nwpu/tree/main I imported the weights file from here and checked the inference results as shown below.

cfg.prepare_train = False
cfg.use_crowd_hat = True
utils.load_crowd_hat(os.path.join(cfg.weights_root, 'count_decoder.pth'),
                        os.path.join(cfg.weights_root, 'nms_decoder.pth'))
if not os.path.exists(cfg.result_root):
    os.mkdir(cfg.result_root)
txt_before = open(os.path.join(cfg.result_root, 'localization_before.txt'), 'w')
txt_after = open(os.path.join(cfg.result_root, 'localization_after.txt'), 'w')
checkpoint_path = 'weights/scale_4_epoch_41.pth'
model = LSCCNN()
checkpoint = torch.load(checkpoint_path)['state_dict']
model.load_state_dict(checkpoint)
model.cuda().eval()


nms_threshold = 0.3
img_path = 'test_image.png'
image = cv2.imread(img_path)
resized_image, ratio = utils.resize_image(image)
resized_image = cv2.cvtColor(resized_image, cv2.COLOR_BGR2RGB)
with torch.no_grad():
    pred_dot_map, pred_box_map, img_out, count = model.predict_single_image(resized_image, nms_thresh=nms_threshold)

pred_dot_map = cv2.resize(pred_dot_map, (resized_image.shape[1], resized_image.shape[0]))
dots = np.where(pred_dot_map > 0.5)
for i in range(len(dots[0])):
    cv2.circle(resized_image, (dots[1][i], dots[0][i]), 2, (0, 255, 0), -1)
cv2.imwrite('output.png', img_out[:,:,::-1])
cv2.imwrite('test.png', resized_image[:,:,::-1])

image

It is confirmed that the bounding box is not drawn exactly at the head position.

am i doing something wrong?

thank you.