current_masks = masks[mask, :, :].copy() numpy.core._exceptions.MemoryError: Unable to allocate 5.31 GiB for an array with shape (340, 4729, 3547) and data type uint8
本来以为是模型参数设置不合理,导致运行内存爆炸,但在设置num_works = 0 batchsize=1的条件后问题依然存在。
然后发现报错的数组大小不合理,远大于我的图片大小,debug找原因,发现340是我的单张图片的目标数,没办法就这么多,图像尺寸却比我的图片大好2 3倍,这就是导致内存爆炸的原因。
解决办法:找到expand类,其是用来扩展图片大小的,修改参数ratio为1到1.5
class Expand(object): def __init__(self, mean): self.mean = mean def __call__(self, image, masks, boxes, labels): if random.randint(2): return image, masks, boxes, labels height, width, depth = image.shape ratio = random.uniform(1, 1.5)#(1,4) left = random.uniform(0, width*ratio - width) top = random.uniform(0, height*ratio - height)