Abstract The alpha magnetic spectrometer (AMS) is a high-precision particle detector onboard the International Space Station containing six different subdetectors. The transition radiation detector and electromagnetic calorimeter (ECAL) are used to separate electrons/positrons from the abundant cosmic-ray proton background. The positron flux measured in space by AMS falls with a power law which unexpectedly softens above 25 GeV and then hardens above 280 GeV. Several theoretical models try to explain these phenomena, and a more accurate measurement of positrons at higher energies is needed to help test them. The currently used methods to reject the proton background at high energies involve extrapolating shower features from the ECAL to use as inputs for boosted decision tree and likelihood classifiers. We present a new approach for particle identification with the AMS ECAL using deep learning (DL). By taking the energy deposition within all the ECAL cells as an input and treating them as pixels in an image-like format, we train an MLP, a CNN, and multiple ResNets and convolutional vision transformers (CvTs) as shower classifiers. Proton rejection performance is evaluated using Monte Carlo (MC) events and ISS data separately. For MC, using events with a reconstructed energy between 0.2–2 TeV, at 90% electron accuracy, the proton rejection power of our CvT model is more than five times that of the other DL models. Similarly, for ISS data with a reconstructed energy between 50–70 GeV, the proton rejection power of our CvT model is more than 2.5 times that of the other DL models.