[Python] how to convert a PIL image to a pytorch tensor for py-feat

Discussão em 'Python' iniciado por Stack, Dezembro 19, 2024.

  1. Stack

    Stack Membro Participativo

    i need to convert a pil image into a pytorch tensor to use it in Detector.detect() (py-feat) but i got this error in line where i call detect():


    RuntimeError: Given groups=1, weight of size [64, 3, 3, 3], expected input[1, 1, 112, 112] to have 3 channels, but got 1 channels instead
    ​

    however, if i check how tensor looks like using check_tensor() after converting, it looks just fine

    here's the code:

    def check_tensor(self, frame_tensor):
    frame_numpy = frame_tensor.squeeze(0).permute(1, 2, 0).byte().numpy()
    frame_numpy_bgr = cv2.cvtColor(frame_numpy, cv2.COLOR_RGB2BGR)
    cv2.imshow("Frame", frame_numpy_bgr)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

    def analyze_image(self, image_path):

    img = Image.open(image_path)
    tensor_image = F.pil_to_tensor(img)
    orig_prediction = self.detector.detect(inputs=tensor_image, data_type="tensor")


    how can i fix this?

    Continue reading...

Compartilhe esta Página