kagle_trainer.py 978 字节
Newer Older
X
xiexionghang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
import sys
import time
from abc import ABCMeta, abstractmethod

class Trainer(object):
    __metaclass__=ABCMeta
    def __init__(self, config):
        self._status_processor = {}
        self._context = {'status': 'uninit', 'is_exit': False}
       
    def regist_context_processor(self, status_name, processor):
        self._status_processor[status_name] = processor

    def context_process(self, context):
        if context['status'] in self._status_processor:
            self._status_processor[context['status']](context)
        else:
            self.other_status_processor(context)
    
    def other_status_processor(self, context):
        print('unknow context_status:%s, do nothing' % context['status'])
	time.sleep(60)

    def reload_train_context(self):
        pass

    def run(self):
        while True:
            self.reload_train_context()
            self.context_process(self._context)
            if self._context['is_exit']:
                break