MAFAT Satellite Vision Challenge Forum

Go back to competition Back to thread list Post in this thread

> Can't run predict on a tiff image

I am trying to use the model.predict function after successfully use model.load (everything on google colab).

I am encountering this error:
OpenCV(4.7.0) /io/opencv/modules/imgproc/src/resize.cpp:3940: error: (-215:Assertion failed) func != 0 in function 'resize'
this is coming from 'inference_detector_by_patches(self.model, img, [640], [320], [1.0], 0.3)' in the model.predit function

I tried to use a lot of methods to give the input image correctly and anything failed:
IMAGE_PATH = r"/content/drive/MyDrive/MAFAT Model/data/images/126_1280_5120.tiff"
1.
import tifffile as tiff
img = tiff.imread(IMAGE_PATH)
2.
import mmcv
img = mmcv.imread(IMAGE_PATH)
3.
# Load the TIFF file as a 16-bit grayscale image
img_gray = cv2.imread(IMAGE_PATH, cv2.IMREAD_UNCHANGED)
# Convert the 16-bit grayscale image to a 16-bit RGB image
img = cv2.cvtColor(img_gray, cv2.COLOR_GRAY2RGB)

and I ran into another error when used:
1.
from PIL import Image
img = Image.open(IMAGE_PATH)
2.
from PIL import Image
import torch
import torchvision.transforms as transforms
img = Image.open(IMAGE_PATH)
transform = transforms.Compose([
transforms.ToTensor()
])
tensor = transform(img)
device = torch.device('cpu')
tensor = tensor.to(device)
tensor = tensor.view(1280, 1280)
# Use tensor instead of img in the predict

the other error:
/usr/local/lib/python3.8/dist-packages/mmrotate/core/post_processing/bbox_nms_rotated.py in multiclass_nms_rotated(multi_bboxes, multi_scores, score_thr, nms, max_num, score_factors, return_inds)
56
57 inds = valid_mask.nonzero(as_tuple=False).squeeze(1)
---> 58 bboxes, scores, labels = bboxes[inds], scores[inds], labels[inds]
59
60 if bboxes.numel() == 0:

RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

Thank you and have a great day (:

Posted by: hadarsnorlax @ Feb. 24, 2023, 2:10 p.m.

Hi,
It seems the third option needs to work.
The "cv2.imread" function does not throw any error if the filename is wrong, so please ensure the following:
1. You wrote the right path, and it is possible to read files from there.
2. The "img" is not a 'nonetype' object .
3. In the model.predict method, there is a conversion to 3 channels:
img = np.stack((img, )*3, axis=-1)
make sure you didn't convert twice - before that method and in this method.
Neta,
MAFAT Challenge Team

Posted by: MAFAT_Challenge @ Feb. 26, 2023, 9:45 a.m.

Yes it all looks fine but it still won't work. The image is right there, the path is fine, and I'm not doing anything else otherwise than read the tiff image and put it inside the predict function (after the load). Do you have any ideas to check this out?

Posted by: hadarsnorlax @ Feb. 26, 2023, 10:12 a.m.

Hi,
We were unable to reproduce your error, however, we have a short code snippet demonstrating the inference pipeline (without statistic calibration and metadata):

from model import model
import cv2
image_path = '/content/images/126_0_1280.tiff'
predictor = model()
predictor.load('/content')
img = cv2.imread(image_path, -1)
print(img.shape)
res = predictor.predict(img, None)
print(res)

We hope this example clears thing out,
Good luck,
MAFAT Challenge Team

Posted by: MAFAT_Challenge @ Feb. 27, 2023, 6:47 a.m.

Thank you, I will try it (:

Posted by: hadarsnorlax @ Feb. 27, 2023, 9:35 a.m.

I tried it exactly the same as you mentioned and it's still won't work:

IMAGE_PATH = r"/content/drive/MyDrive/MAFAT Model/data/images/126_1280_5120.tiff"

img = cv2.imread(IMAGE_PATH, -1)
print(img.shape)

if img is None:
print('Failed to load image')

# (1280, 1280)

> detections = model.predict(img, None)
print(detections)

failed on 'result = inference_detector_by_patches(self.model, img, [640], [320], [1.0], 0.3)'

/usr/local/lib/python3.8/dist-packages/mmrotate/core/post_processing/bbox_nms_rotated.py in multiclass_nms_rotated(multi_bboxes, multi_scores, score_thr, nms, max_num, score_factors, return_inds)
56
57 inds = valid_mask.nonzero(as_tuple=False).squeeze(1)
---> 58 bboxes, scores, labels = bboxes[inds], scores[inds], labels[inds]
59
60 if bboxes.numel() == 0:

RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)

Is there any way you can send me the images with the predictions so we would know what to focus on when building the model?
Thanks (:

Posted by: hadarsnorlax @ March 3, 2023, 11:22 a.m.

Hi,
First, please make sure you have installed all the required packages with the correct version.
Second, you can find a prediction sample for one frame at the "Prediction and Evaluation" tab (list of 13 lists for a single frame).
Neta,
MAFAT Challenge Team

Posted by: MAFAT_Challenge @ March 5, 2023, 11:43 a.m.
Post in this thread