Python 3.x 通过tensorflow旋转创建增强训练数据

Python 3.x 通过tensorflow旋转创建增强训练数据,python-3.x,tensorflow,conv-neural-network,tensor,Python 3.x,Tensorflow,Conv Neural Network,Tensor,从最近的tensorflow和cnn开始,我希望训练一个简单的网络来向上旋转功能 我有一个1k向上的图像数据集,使用tensorflow.contrib.image.rotate我想用随机角度旋转它们。 在的行内,但带有tensorflow而不是keras的东西 其想法是从1k图像数据集中的每个图像创建N旋转训练示例。每个图像的形状为30x30x1(黑白) 现在的问题是,sess.run(rotated\u image)行需要很长时间才能执行。e、 g仅为1k中的每一个创建5个示例已运行超过30

从最近的
tensorflow
cnn
开始,我希望训练一个简单的网络来向上旋转功能

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

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

现在的问题是,
sess.run(rotated\u image)
行需要很长时间才能执行。e、 g仅为1k中的每一个创建5个示例已运行超过30分钟(在cpu上)。
如果我简单地删除这一行,图像将在一分钟内生成


我想有一种方法可以将数据作为张量存储和使用,而不是像我到目前为止所做的那样将它们转换回nArray,或者可能有一个更快的函数来计算张量?

问题是,您正在为
中的每个图像创建一个旋转操作符,以增强每个图像,产生一个潜在的非常大的网络

解决方案是创建一个单独的旋转op,然后依次应用于图像。大致如下:

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

谢谢,现在一切顺利,我确实学到了一些重要的东西!
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