There's a tiny mistake in the function show_mask_on_image. The heatmap you get from cv2 is in bgr format, so you need to convert it to rgb before adding to the img:
def show_mask_on_image(img, mask):
...
heatmap = cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB)
cam = heatmap + np.float32(img)
...