How to use a pytorch tensor or an openCV iamge correctly as input for for OpenAi CLIP?
I tried the following but this didn't work so far :
device = "cuda" if torch.cuda.is_available() else "cpu"
clip_model, clip_preprocess = clip.load("ViT-B/32", device=device)
clip_preprocess(torch.from_numpy(OpenCVImage)).unsqueeze(0).to(device)
- the preprocess step fails with message
Process finished with exit code 137 (interrupted by signal 9: SIGKILL)
- openCVImage is a object that was already processed with cv2.COLOR_BGR2RGB
If you read the transforms code for
CLIP
, it shows that you need a PIL Image Object not a Numpy Array or Torch Tensor. These linesIn PyTorch, mostly Transforms are written for PIL not for Numpy or Torch due to performance and good results. So you have to convert each Image to PIL first via
or you can simply use the last transform manually like