Abstract: A method, performed by an electronic device, of generating a virtual defect image includes training a virtual defect image generation model based at least on a first normal image and a defect image of a first product, and a user input, and generating a virtual defect image from a second normal image of a second product by using the trained virtual defect image generation model.