Imported from https://github.com/aleju/gan-error-avoidance