我目前正在训练基于方向的模型。我希望能够训练一个模型来判断物体的估计方向。目前,我在 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
这些是与训练期间的数据增强相关的代码。如果我的理论是正确的,我想咨询你的意见?如果是这样,我如何禁用翻转操作但保留其余的数据扩充?谢谢!