Bacterial infections can easily occur when patients mishandle wounds or eat moldy food. The prompt diagnosis of a bacterial infection could effectively reduce the risk of possible anatomical damage. However, non-invasive early detection of bacterial infections is difficult to achieve due to the lack of favorable tools. Here, we designed two hNQO1 fluorescent probes (RX2 and RX3) to visualize bacterial infection after deep learning on the pathogenesis of bacterial infection. RX2 and RX3 enable early detection of bacterial infection and are verified to be, respectively, suitable for fluorescence imaging (FLI) and photoacoustic imaging (PAI) by comparing the signal-to-background ratio of both probes in a mouse model of myositis caused by Escherichia coli infection. In view of the difference in penetration depth between the two imaging modalities, we further applied RX2 for FLI of E. coli-infected wounds and RX3 for PAI of E. coli-infected inflammatory bowel disease, suggesting the great potential of both probes for early diagnosis of bacterial infections.