繁体   English   中英

如何禁用 Darkflow YOLOv2 上的图像翻转?

[英]How do i disable the flipping of images on Darkflow YOLOv2?

我目前正在训练一个基于方向的模型。 我希望能够训练一个可以判断物体估计方向的模型。 目前,我在 1000 epoch 左右,准确性不好。 我的理论是翻转操作似乎会导致模型不准确,因为 90 度的方向可能会翻转到 -90 度。 因此,这两个独立的类会相互混淆。

def imcv2_affine_trans(im):
    # Scale and translate
    h, w, c = im.shape
    scale = np.random.uniform() / 10. + 1.
    max_offx = (scale-1.) * w
    max_offy = (scale-1.) * h
    offx = int(np.random.uniform() * max_offx)
    offy = int(np.random.uniform() * max_offy)

    im = cv2.resize(im, (0,0), fx = scale, fy = scale)
    im = im[offy : (offy + h), offx : (offx + w)]
    flip = np.random.binomial(1, .5)
    if flip: im = cv2.flip(im, 1)
    return im, [w, h, c], [scale, [offx, offy], flip]

def preprocess(self, im, allobj = None):
    """
    Takes an image, return it as a numpy tensor that is readily
    to be fed into tfnet. If there is an accompanied annotation (allobj),
    meaning this preprocessing is serving the train process, then this
    image will be transformed with random noise to augment training data,
    using scale, translation, flipping and recolor. The accompanied
    parsed annotation (allobj) will also be modified accordingly.
    """
    if type(im) is not np.ndarray:
        im = cv2.imread(im)

    if allobj is not None: # in training mode
        result = imcv2_affine_trans(im)
        im, dims, trans_param = result
        scale, offs, flip = trans_param
        for obj in allobj:
            _fix(obj, dims, scale, offs)
            if not flip: continue
            obj_1_ =  obj[1]
            obj[1] = dims[0] - obj[3]
            obj[3] = dims[0] - obj_1_
        im = imcv2_recolor(im)

    im = self.resize_input(im)
    if allobj is None: return im
    return im#, np.array(im) # for unit testing

这些是与训练期间数据增强相关的代码。 如果我的理论是对的,我想咨询您的意见? 如果是这样,我如何禁用翻转操作但保留其余的数据增强? 谢谢!

我有同样的问题,但我找到了答案。 我们可以在darkflow\\darkflow\\net\\yolo\\predict.py上看到“from ...utils.im_transform import imcv2_recolor, imcv2_affine_trans”

函数 imcv2_affine_trans 在 darkflow\\darkflow\\utils\\im_transform.py 中定义

所以我们可以像下面这样禁用翻转。

def imcv2_affine_trans(im):
   # Scale and translate
   h, w, c = im.shape
   scale = np.random.uniform() / 10. + 1.
   max_offx = (scale-1.) * w
   max_offy = (scale-1.) * h
   offx = int(np.random.uniform() * max_offx)
   offy = int(np.random.uniform() * max_offy)

   im = cv2.resize(im, (0,0), fx = scale, fy = scale)
   im = im[offy : (offy + h), offx : (offx + w)]
   flip = 0#np.random.binomial(1, .5)
   #if flip: im = cv2.flip(im, 1)
   return im, [w, h, c], [scale, [offx, offy], flip]

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM