TensorFlow 中的数据增强

数据挖掘 深度学习 张量流 数据增强
2022-02-13 03:29:08

我正在尝试复制一个用于面部关键点检测的网络,如以下链接Daniel Nouri 在 KFKD 上的博客该博客使用千层面,但我正在尝试使用 Tensorflow。我无法遵循在 Tensorflow 中执行数据增强的部分。

我看到的所有方法要么在训练之前进行了增强,要么只应用于 X 值而不应用于 Y。

我想找到博客中使用的 FlipBatchIterator 类的替换

from nolearn.lasagne import BatchIterator

class FlipBatchIterator(BatchIterator):
flip_indices = [
    (0, 2), (1, 3),
    (4, 8), (5, 9), (6, 10), (7, 11),
    (12, 16), (13, 17), (14, 18), (15, 19),
    (22, 24), (23, 25),
    ]

def transform(self, Xb, yb):
    Xb, yb = super(FlipBatchIterator, self).transform(Xb, yb)

    # Flip half of the images in this batch at random:
    bs = Xb.shape[0]
    indices = np.random.choice(bs, bs / 2, replace=False)
    Xb[indices] = Xb[indices, :, :, ::-1]

    if yb is not None:
        # Horizontal flip of all x coordinates:
        yb[indices, ::2] = yb[indices, ::2] * -1

        # Swap places, e.g. left_eye_center_x -> right_eye_center_x
        for a, b in self.flip_indices:
            yb[indices, a], yb[indices, b] = (
                yb[indices, b], yb[indices, a])

    return Xb, yb



net3 = NeuralNet(
# ...
regression=True,
batch_iterator_train=FlipBatchIterator(batch_size=128),
max_epochs=3000,
verbose=1,
)
0个回答
没有发现任何回复~