A primary school teacher who filmed children as they changed for swimming lessons has been jailed for six months.
But a judge said he was confident Richard Oldham, 32, was "man enough" to wrestle his demons as he passed sentence at Leeds Crown Court.
Oldham admitted taking the footage on his mobile phone when he was a teacher in York.
He also admitted touching two pupils inappropriately and possessing hundreds of indecent images of children on his computer.
Police called Oldham a "predatory paedophile"
Judge Rodney Jameson told him: "You have demons to wrestle with. I'm confident you're man enough to do it."
Judge Jameson heard that Oldham had been a gifted teacher and said to him: "It's a loss to the community. Good teachers are not a rare commodity but when they're found they should be treasured."
The judge said: "This is, in the classic sense of the word, a tragedy - that somebody with your ability, and the good in you, was not able to control successfully instincts that led you to commit these offences."
He told Oldham the six-month sentence "for you will be a very severe punishment".
He said the offences "strike at the root of the the relationship that children should have with their teachers".
Judge Jameson said he was particularly concerned about the filming at the swimming baths.
He said many of the children featured might never be identified and many people in York will wonder whether Oldham possessed images of them.
"This is a crime that's likely to have continuing consequences for very many people," the judge said.
Aisha Wadoodi, prosecuting, said Oldham's offending spanned eight years.
She said it was uncovered in September last year after a 10-year-old boy complained that the teacher touched him during a lesson.
The court heard the touching was inappropriate but was over his clothes and did not involve his genitals.
Once the case received media coverage, another 10-year-old boy, at a different school, came forward to say he had been touched by Oldham between September 2010 and July last year.
The court heard how this boy told his mother: "I bet that's Mr Oldham. He's a right weirdo. He used to touch all the lads' legs."
After Oldham was arrested, police found computer equipment at his home which contained more than 2,000 indecent images of children. Although most were at the lower levels, some of the images were level four, which the judge described as "the rape of children".
Ms Wadoodi said the filming at the swimming lessons concentrated on the children's genitals. She said Oldham would also talk to the children about erections and pornography.
Alisdair Williamson, defending, said his client was a "young man who has struggled with dark desires".
Mr Williamson said Oldham "crucially came to realise his curiosity results from a sexual interest in boys".
He said: "He clearly wants treatment and is susceptible to treatment."
The barrister said some the indecent images were taken from a publicly available website and his client used them as drawing models.
Oldham, of Holsworthy, Devon, stood in the dock to be sentenced wearing a grey suit, light blue shirt and dark blue tie.
He showed no emotion as he was led away, watched by a public gallery packed with his friends and family.
Judge Jameson imposed a Sexual Offences Prevention Order and ordered Oldham to sign the Sex Offenders Register for 10 years.
He was banned for life from working with children.
Detective Sergeant Adam Normanton, of North Yorkshire Police, said: "Richard Oldham is a predatory paedophile.
"It is quite apparent by evidence obtained during the course of the investigation that he actively pursued a career in teaching to enable himself a position where he could abuse children for his own sexual gratification.
"His wickedness is such that he particularly abused the children who he thought would either not tell anyone or would not be believed.
"Oldham's guilty pleas on 5 August 2013 were the first time he had acknowledged his offending. When questioned by police he dismissed the evidence of the children and tried to distance himself from the catalogue of child abuse images on his computer including the videos he had himself recorded.
"Oldham tried to portray himself as the model teacher to the police, his colleagues and his family. He was in fact the opposite, he was every parent's worst nightmare and prison is the right place for him.
"I would like to thank the children and their families for coming forward to the police and I acknowledge and praise their courage as they prepared to give evidence at trial."