Designing an infrared machine vision system that can efficiently perceive, convert, and process a massive amount of data remains a challenge. Here, the authors present a retina-inspired 2D optoelectronic device based on van der Waals heterostructure that can perform the data perception and spike-encoding simultaneously for night vision, sensing, spectroscopy, and free-space communications.