I have a set of rois and want to generate a set of mask tensor using the rois. I use the below code, but it is slow that cost 0.3s. how can i quickly get the masks.
masks = torch.zeros((rois.size(0), w, h), dtype=torch.float32)
rois[:,1] = torch.max(torch.zeros(rois.size(0)).cuda(), rois[:, 1])
rois[:,2] = torch.max(torch.zeros(rois.size(0)).cuda(), rois[:, 2])
rois[:,3] = torch.min(torch.zeros(rois.size(0)).cuda() + h -1, rois[:, 3]) + 1
rois[:,4] = torch.min(torch.zeros(rois.size(0)).cuda() + w -1, rois[:, 4]) + 1

rois = rois.long()
pdb.set_trace()

for i in range(rois.size(0)):
    roi = rois[i]
    mask = torch.zeros((w, h), dtype=torch.float32)

    mask[roi[2]:roi[4]+1, roi[1]:roi[3]+1] = 1
    masks[i,:,:] = mask
    #save(mask, 'images/' + str(i) + '.png')

thank you for your reply