在 Tensorflow 2.4 下运行 Mask R-CNN

原版的 Mask R-CNN: GitHub - matterport/Mask_RCNN: Mask R-CNN for object detection and instance segmentation on Keras and TensorFlow

的运行环境是 Tensorflow 1.x,我使用的显卡是 Nvidia 3090Ti,当运行 train.py 训练模型时出错:

failed to run cuBLAS routine: CUBLAS_STATUS_EXECUTION_FAILED

did not memzero GPU location; source: 0x70bc90ffbaf0

did not allocate timer: 0x70bc90ffbb20

出错的原因是 NVidia 3090Ti 显卡与 Tensorflow 1.14/15 不兼容。

为了能够在 Tensorflow 2.4 环境下使用 Mask R-CNN,设置如下:

1. 从原版Mask R-CNN 地址下载其一个分支:
https://github.com/matterport/Mask_RCNN/tree/295c802f0bebbc4a34ec4855f4960a52a701271d

2. 修改 rcnn/model.py,找到代码:

```

if model.uses_learning_phase and not isinstance(K.learning_phase(), int):

```

替换为:

```

if not isinstance(K.learning_phase(), int):

```

3. 在 model.py 中添加:

```

class AnchorsLayer(KL.Layer):

        def __init__(self, anchors, name="anchors", **kwargs):

                super(AnchorsLayer, self).__init__(name=name, **kwargs)

                self.anchors = tf.Variable(anchors)

        def call(self, dummy):

                return self.anchors

        def get_config(self):

                config = super(AnchorsLayer, self).get_config()

                return config

```

找到代码:

```

anchors = KL.Lambda(lambda x: tf.Variable(anchors), name="anchors")(input_image)

```

替换为:

```

anchors = AnchorsLayer(anchors, name="anchors")(input_image)

```

4. 确保主要python 包的版本:

tensorflow 2.4.0

keras 2.9.0

numpy 1.23.4

scikit-image 0.16.2

5. python 版本 3.8,CUDA 12.2

6. 运行train.py 时观察控制台信息,如发现无法装载某个 CUDA 库,可以设置 LD_LIBRARY_PATH 环境变量指向该库所在的目录

7. 通过命令 nvidia-smi 观察GPU 使用情况,确保 train.py 使用了 Nvidai GPU

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值