image flip code & some changes for training