Abstract Sleep is an evolutionarily conserved behavior, whose function is unknown. Here, we present a system for deep phenotyping of sleep in Drosophila. We developed a high-resolution video imaging system, coupled with closed-loop laser perturbation and optogenetic stimulation. To quantify sleep-associated microbehaviors, we trained a deep-learning network to annotate freely moving flies and developed a semi-supervised computational pipeline to classify behaviors.