Finish db.py and training.py.