Faster/Mask R-CNN代码测试问题汇总

运行环境:

Windows下TensorFlow2.0+Keras

  1. 问题一:版本升级导致的错误(主要是本人小白菜。。。)
    TensorFlow2.0与1.X的API命称和参数有所改变。例如:
1  tf.to_float,tf.to_int32 => tf.cast(x,dtype) or tf.compat.v1.to_float
2  tf.log => tf.math.log
3  tf.rint => tf.math.rint
4  tf.sets.set_intersection => tf.sets.intersection
5  tf.sparse_tensor_to_dense => tf.sparse.to_dense
6  tf.random_shuffle => tf.random.shuffle
7  tf.nn.softmax_cross_entropy_with_logits_v2 => tf.nn.softmax_cross_entropy_with_logits
8  tf.reduce_mean => tf.math.reduce_mean
9  tf.add_n => tf.math.add_n

 。。。。。。


###########################不理解的问题###############################
报错:using a tf.Tensor as a Python bool is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.


if layer.output in self.keras_model.losses:
	continue
报错:using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
语句作用:逐表添加loss函数
解决方法:
1		exists_names=[] # 创建空表,有就不再添加

        for name in loss_names:
            layer = self.keras_model.get_layer(name)
            #if layer is None or layer.output in self.keras_model.losses:
            #    continue
2            if name in exists_names:
                #存在就转到下一次循环
                contine
            #入表
3            exists_names.append(name)
描述:都是为了添加需要的loss,但我用2.0版本的时候的layer.output和self.keras_model.losses两个组合时会报错,所以重建了个列表进行添加操作。
参考:这位兄弟让我很感激:https://blog.csdn.net/na_fantastic/article/details/102548647

############ keras2.3.0有API改动,改用add_metric##########
报错:AttributeError: ‘Model’ object has no attribute ‘metrics_tensors’

############# keras2.3.0有API改动,改用add_metric##########

            #self.keras_model.metrics_names.append(name)
            #self.keras_model.metrics_tensors.append(tf.math.reduce_mean(layer.output, keepdims=True))
            self.keras_model.add_metric(layer.output, name=name)
注意:add_metric(value, aggregation=None, name=None)中的参数aggregation有的版本可能没有。比如我的:
 def add_metric(self, value, name=None):
        """Adds metric tensor to the layer.

        # Arguments
            value: Metric tensor.
            name: String metric name.

################scipy 版本问题############################
报错:module ‘scipy.misc’ has no attribute ‘imresize’

np.round(scipy.misc.imresize(class_mask.astype(float), (gt_h, gt_w),
                                             interp='nearest') / 255.0).astype(bool)
描述:这个版本没有imresize这个函数
解决方法:检查是否有pillow 并且 scipy==1.2.1 退回到1.21版本(这方法有点无脑缺啥补啥。。。)

TypeError: crop_and_resize_v2() got an unexpected keyword argument ‘box_ind’

box_ind参数名改为 box_indices

output = tf.image.crop_and_resize(image=features,
                                          boxes=rois,
                                          box_ind=batch_index,
                                          box_indices=batch_index,
       ## box_ind参数名改为 box_indices                           
                                          crop_size=self.pool_size)

TypeError: unhashable type: ‘ListWrapper’

 # 增加损失函数,首先清除之前的,防止重复
    keras_model._losses = []
    keras_model._per_input_losses = {}
    layer_exists_name = []
    for name in loss_names:
        layer = keras_model.get_layer(name)
        if layer is None or name in layer_exists_name:
            continue
        layer_exists_name.append(name)
        loss = (tf.math.reduce_mean(layer.output, keepdims=True)
                * loss_weights.get(name, 1.))
        keras_model.add_loss(loss)
# 增加 loss 时出现报错TypeError: unhashable type: 'ListWrapper'
列表不可哈希,这里错误来源不太懂
   # keras_model._losses = []
   # keras_model._per_input_losses = {}
  注释掉这两句就行
  1. 显存不足:

  2. 后续补充

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
R-CNN(Region-based Convolutional Neural Networks)是一种目标检测算法,它通过两个阶段来检测图像中的目标物体。首先,R-CNN使用选择性搜索(Selective Search)算法生成一系列候选区域,然后对每个候选区域进行卷积神经网络(CNN)特征提取和分类。R-CNN的主要缺点是速度较慢,因为每个候选区域都需要独立地进行CNN特征提取和分类。 Fast R-CNN是对R-CNN的改进,它通过引入RoI池化层(Region of Interest pooling)来解决R-CNN中重复计算的问题。RoI池化层可以将不同大小的候选区域映射为固定大小的特征图,从而使得所有候选区域可以共享相同的特征提取过程。这样一来,Fast R-CNN相比于R-CNN具有更快的速度。 Faster R-CNN是对Fast R-CNN的进一步改进,它引入了一个称为Region Proposal Network(RPN)的子网络来生成候选区域。RPN通过滑动窗口在特征图上提取候选区域,并为每个候选区域分配一个得分,然后根据得分进行筛选和排序。这种端到端的训练方式使得Faster R-CNN在目标检测任务上具有更高的准确性和更快的速度。 Mask R-CNN是在Faster R-CNN的基础上进一步发展的,它不仅可以进行目标检测,还可以进行实例分割。Mask R-CNNFaster R-CNN的基础上增加了一个分支网络,用于预测每个候选区域中目标物体的像素级掩码。这使得Mask R-CNN能够同时获得目标的位置信息和像素级别的语义信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值