【问题标题】:Creating augmented training data by tensorflow rotation通过张量流旋转创建增强的训练数据
【发布时间】:2018-05-03 13:06:38
【问题描述】:

最近从tensorflowcnn 开始,我希望训练一个简单的网络来向上旋转特征。

我有一个 1k 向上的图像数据集并使用 tensorflow.contrib.image.rotate 我想以随机角度旋转它们。 在RotNet 的行内,但使用tensorflow 而不是keras

这个想法是从 1k 个图像数据集中的每一个创建 N 旋转训练示例。每个图像的形状为 30x30x1(黑白)。

with tf.Session() as sess:
    for curr in range(oriented_data.shape[0]):
        curr_image = loaded_oriented_data[curr]
        for i in range(augment_each_image):
            rotation_angle = np.random.randint(360)
            rotated_image = tfci.rotate(curr_image, np.float(rotation_angle) * math.pi/180.)
            training_data[curr + i] = sess.run(rotated_image)
            labels[curr + i] = rotation_angle

现在的问题是sess.run(rotated_image) 行需要很长时间才能执行。例如,为 1k 中的每一个仅创建 5 个示例已运行超过 30 分钟(在 cpu 上)。
如果我只是删除该行,图像会在一分钟内生成。

我想有一种方法可以将数据作为张量存储和处理,而不是像我迄今为止所做的那样将它们转换回 ndarray,或者是否有更快的函数来评估张量?

【问题讨论】:

    标签: python-3.x tensorflow conv-neural-network tensor


    【解决方案1】:

    问题是您正在为augment_each_image 中的每个图像创建一个旋转运算符,从而产生一个可能非常大的网络。

    解决方案是创建一个 single 旋转操作,您可以将其连续应用于图像。类似的东西:

    im_ph = tf.placeholder(...)
    ang_ph = tf.placeholder(...)
    rot_op = tfci.rotate(im_ph, ang_ph)
    
    with tf.Session() as sess:
      for curr in range(oriented_data.shape[0]):
        curr_image = loaded_oriented_data[curr]
          for i in range(augment_each_image):
            rotation_angle = np.random.randint(360)
            rotated_image = sess.run(rot_op, {im_ph: curr_image, ang_ph: np.float(rotation_angle) * math.pi/180.})
            training_data[curr + i] = rotated_image
            labels[curr + i] = rotation_angle
    

    【讨论】:

    • 谢谢,现在运行顺利,我肯定学到了一些重要的东西!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    相关资源
    最近更新 更多