如何在matterport/Mask RCNN示例中减小批处理大小和图像形状?

2024-10-01 04:44:25 发布

您现在位置:Python中文网/ 问答频道 /正文

当我运行以下代码时,我得到以下错误

from mrcnn.config import Config

class KangarooConfig(Config):
    # define the name of the configuration
    NAME = "kangaroo_cfg"
    # number of classes (background + kangaroo)
    NUM_CLASSES = 1 + 1
    # number of training steps per epoch
    STEPS_PER_EPOCH = 131


from mrcnn.model import MaskRCNN

# prepare config
config = KangarooConfig()
config.display()
# define the model
model = MaskRCNN(mode='training', model_dir='./', config=config)
model.keras_model.metrics_tensors = []


# load weights (mscoco) and exclude the output layers
model.load_weights('mask_rcnn_coco.h5', by_name=True, exclude=["mrcnn_class_logits", "mrcnn_bbox_fc",  "mrcnn_bbox", "mrcnn_mask"] )
# train weights (output layers or 'heads')
model.train(train_set, test_set, learning_rate=config.LEARNING_RATE, epochs=5, layers='heads' )

错误:

ResourceExhaustedError: 2 root error(s) found. (0) Resource exhausted: OOM when allocating tensor with shape[400,14,14,256] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc

在这种情况下,如何减小批处理大小和图像大小?你知道吗

Output of Code


Tags: ofthefromimportconfigmodellayers错误
1条回答
网友
1楼 · 发布于 2024-10-01 04:44:25

转到Config.py文件并更改

 IMAGE_MIN_DIM = 800 to 400
 IMAGE_MAX_DIM = 1024 to 512

以及

IMAGES_PER_GPU = 2 to 1
IMAGE_RESIZE_MODE = "square" to "none"

相关问题 更多 >