Deep-learning real-time phase retrieval of imperfect diffraction patterns from X-ray free-electron lasers