Your method works fine using random inputs:
def HPF(img):
    image = np.array(img)
    kernel = np.array(
        [[1,4,7,4,1],
         [4,16,26,16,4],
         [7,26,41,26,7],
         [4,16,26,16,4],
         [1,4,7,4,1]])
    kernel = kernel/273
    img_rst = cv2.filter2D(np.float32(image),-1,kernel)
    new_image = img_rst
    return new_image

x = PIL.Image.fromarray(np.random.uniform(0, 256, (224, 224, 3)).astype(np.uint8))

transform = transforms.Lambda(HPF)
img = transform(x)

plt.imshow(img.astype(np.uint8))