我使用了2种不同的方法来旋转图像,从这个 疑问. 在不知不觉中,我已经浪费了一个星期的时间,试图找出为什么我的keras发生器慢了这么多,所以我想我会分享。
我尝试的第一个图像旋转,是相当缓慢的。
import time
t0 = time.time()
img1= ndimage.rotate(img1, 210)
t1 = time.time()
total1 = t1-t0
print(total1)
然后我试了这个旋转。
def rotate(img, angle):
row, col, channel = img.shape
rotation_point = (row / 2, col / 2)
rotation_matrix = cv2.getRotationMatrix2D(rotation_point, angle, 1)
rotated_img = cv2.warpAffine(img, rotation_matrix, (col, row))
return rotated_img
t0 = time.time()
img1 = rotate(img1, 210)
t1 = time.time()
total2 = t1-t0
print('def: ', str(total2))
print(total2/total1)
当我运行第二种旋转图像的方法时,它给我带来了14倍的加速,这为我节省了很多时间,希望也能帮助你。