Example #1
0
def handler(sig, frame):
    sd = Shared()
    logger = sd.getLogger()
    logger.debug("\r\r\r\r\r")
    print('...closing...patient...')

    while sd.getFlag('safeExit') != 0:
        pass
    sd.setFlag('nowExit', True)
Example #2
0
def main(argv=None):
    sd = Shared()
    # 全局唯一日志句柄
    logger = sd.getLogger()
    # 当前操作是否可打断
    sd.setFlag('safeExit', 0)
    # 当前是否可退出
    sd.setFlag('nowExit', False)

    # 处理SIGINT信号
    signal.signal(signal.SIGINT, handler)

    # 配置对象
    prop = Prop()
    logger.info(prop.toString())

    # 消息队列,用于中转训练误差信息
    msg_queue = sd.getQueue('msg')
    # 数据队列,用于中转训练数据
    data_queue = sd.getQueue('data')

    # 文件调度对象,加载数据数据
    sched = IOsched(prop, data_queue)
    sched.start()

    # 任务处理对象
    mainfeed = MainFeed(prop, data_queue)
    mainproc = MainProc(prop, mainfeed, msg_queue)
    mainproc.start()

    # 走势图绘制
    if platform.system() == 'Windows':
        render = iRender(msg_queue, prop)

    # 主线程等待终止消息或信号
    while not sd.getFlag('nowExit'):
        if platform.system() == 'Windows':
            render.process()
        else:
            pass
Example #3
0
 def restore(self, path):
     if os.path.exists(path + '/checkpoint'):
         ckpt = tf.train.latest_checkpoint(path)
         self.__logger.debug('checkpoint path is \'%s\'' % ckpt)
         try:
             saver = tf.train.Saver(save_relative_paths=True)
             saver.restore(self.__sess, ckpt)
         except:
             sd = Shared()
             try:
                 overwrite = sd.getFlag('overwrite')
             except:
                 overwrite = None
             if overwrite is not True:
                 cprint(
                     'model[%s] mismatch! current checkpoint will be overwriten,do you want to continue?'
                     % self.__name, 'yellow')
                 cands = ['y', 'yes', 'n', 'no']
                 deci = ''
                 while not (deci in cands):
                     deci = input(cprint('y or n:', 'yellow'))
                     if deci == 'y' or deci == 'yes':
                         sd.setFlag('overwrite', True)
                         return False
                     elif deci == 'n' or deci == 'no':
                         sd.setFlag('overwrite', False)
                         exit(-1)
                     else:
                         self.__logger.warn(
                             'invalid input,please try again...')
             return False
         self.__logger.info('model restored from the latest checkpoint.')
     else:
         self.__logger.warn('checkpoint not found!')
         return False
     return True