modified training image data reader function