Move model DB training to own file to fix pickle issue.

See http://stefaanlippens.net/pickleproblem