Hi everyone,
I am having some trouble running inference on a Mask2Former model which I successfully trained before.
I followed this tutorial here: https://pyimagesearch.com/2023/03/13/train-a-maskformer-segmentation-model-with-hugging-face-transformers/ , replaced the MaskFormer model by the Mask2Former model and trained it on my custom dataset. Unfortunately, when trying to run inference on the trained model, an error message shows up:
RuntimeError: Input type (torch.cuda.ByteTensor) and weight type (torch.cuda.FloatTensor) should be the same
This is my code:
# Load model
# Use GPU if available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Grab the trained model and processor
model = Mask2FormerForUniversalSegmentation.from_pretrained("model.torch").to(device)
processor = Mask2FormerImageProcessor.from_pretrained("pretrained/preprocessor_config.json")
# Use random test image
index = random.randint(0, len(test))
image = test[index]["image"].convert("RGB")
target_size = image.size[::-1]
# Preprocess image
inputs = processor(images=image, return_tensors="pt").to(device)
# Inference
model.eval()
with torch.no_grad():
outputs = model(**inputs)
Any help would be appreciated. Thanks a lot.