jbwang1997 / OBBDetection

OBBDetection is an oriented object detection library, which is based on MMdetection.
Apache License 2.0
522 stars 112 forks source link

关于roi_align_rotated获取特征的问题 #56

Closed qfwysw closed 2 years ago

qfwysw commented 2 years ago

感谢您优质的代码! 我尝试自己调用RoIAlignRotated函数, 我输入的是一张照片, 我自己造了一个roi, 我看了代码知道input的输入应该是[b, c, h, w], roi[b, cw, ch, w, h, theat], 我不清楚哪里出错了, 我尝试同等比例裁剪一块区域下来, 但是好像出了一些问题, 您能给我提供一些建议或例子吗? from PIL import Image import numpy as np import matplotlib.pyplot as plt im = np.array(Image.open('2.jpg'), dtype=np.float)[np.newaxis, ...] # 1, 2160, 3840, 3 print("img.shape: ", im.shape)

plt.imshow(im.squeeze().astype(np.int))

# plt.show()
# print(im.shape)
# sys.exit()
im = im.transpose(0, 3, 1, 2)  # (1, 3, 2160, 3840) b, c, h, w
im = torch.from_numpy(im)
# plt.imshow(im.numpy().squeeze().transpose(1, 2, 0).astype(np.int))
# plt.show()
# print(im.shape)
# sys.exit()
rois = np.array([1, 1249, 2391, 1000, 1000, 0.0], dtype=np.float).reshape(-1, 6)  # b, cw, ch, w, h, theta
rois = torch.from_numpy(rois)
rroi = RoIAlignRotated(500, 1.0)
res = rroi(im, rois)
print("res.shape: ", res.shape)
res = res.numpy().squeeze()
# sys.exit()
res = res.transpose(1, 2, 0).astype(np.int)
print("res.transpose.shape: ", res.shape)
# sys.exit()
# print(res)
plt.imshow(res)
plt.show()
jbwang1997 commented 2 years ago

这里只有一个图片,那么batch的编号应该是0 rois = np.array([0, 1249, 2391, 1000, 1000, 0.0], dtype=np.float).reshape(-1, 6)

qfwysw commented 2 years ago

感谢您的回答, 这解决了我的问题, 十分感谢!!!