Because of rotating image, now the total data num for each epoch is
uncertain. Add an if condition to break the for loop.