When Olivia Lara-Gresty saw the metal detectors at the entrance of Middle School 54 on the Upper West Side, she turned around and ran home to ditch her contraband before joining her sixth-grade class.

The cellphone police had arrived.

Not everyone was so savvy. The Police Department was there to carry out a random sweep for prohibited items, requiring all 900-plus students at the school to walk through metal detectors before entering.

Their total haul included 404 cellphones, 69 iPods, 23 other electronic devices, two knives and one imitation gun.

“People were crying,” said Samantha Haber, 14, an eighth grader.

Officially, the X-ray scans are meant to catch dangerous items. But since the unannounced sweeps began in April 2006, they have mostly detected cellphones, infuriating parents who see them as lifelines and have loudly opposed the checks.