def upload_model(self, extra): model_desc = self.api.simple_request('GenerateNewModelId', api_proto.ModelDescription, api_proto.Empty()) local_extra = { 'model_id': model_desc.id, 'model_hash': model_desc.hash } self.logger.trace('NEW_MODEL_ID', extra=local_extra) cur_checkpoint_dir = os.path.join(self.dir_results, extra['subdir']) storage = self.data_mgr.storage.nns if storage.check_storage_object(model_desc.hash): self.logger.critical('CHECKPOINT_ALREADY_EXISTS', extra=local_extra) raise RuntimeError() storage.write_object(cur_checkpoint_dir, model_desc.hash) model_config_path = osp.join(cur_checkpoint_dir, 'config.json') if osp.isfile(model_config_path): local_extra['model_config'] = sly.json_load(model_config_path) self.logger.info('MODEL_SAVED', extra=local_extra) # don't report TaskStep.UPLOAD because there should be multiple uploads res = { 'model_id': model_desc.id, 'model_hash': model_desc.hash, 'model_config': local_extra.get('model_config', {}) } return res
def download_object_hashes(self, api_method_name): self.logger.info('RECEIVE_OBJECT_HASHES') res_hashes_exts = [(x.hash, x.ext) # ok, default ext is '' for x in self.api.get_stream_with_data(api_method_name, api_proto.NodeObjectHash, api_proto.Empty())] self.logger.info('OBJECT_HASHES_RECEIVED', extra={'obj_cnt': len(res_hashes_exts)}) return res_hashes_exts
def task_main_func(self): try: self.logger.info('IMAGE_STREAMER_INITIALIZED') for gen_event in self.api.get_endless_stream( 'GetGeneralEventsStream', api_proto.GeneralEvent, api_proto.Empty()): event_obj = { 'request_id': gen_event.request_id, 'data': sly.json_loads(gen_event.data.decode('utf-8')), } self.logger.debug('GET_STREAM_IMAGE_CALL', extra=event_obj) self.thread_pool.submit(sly.function_wrapper_nofail, self.stream_image, event_obj) except Exception: extra = { 'event_type': EventType.TASK_CRASHED, 'error': traceback.format_exc().split('\n') } self.logger.critical("IMAGE_STREAMER_CRASHED", extra={**extra})
def get_stop_task(self): for task in self.api.get_endless_stream('GetStopTask', api_proto.Id, api_proto.Empty()): stop_task_id = task.id self.logger.debug('GET_STOP_TASK', extra={'task_id': stop_task_id}) self.stop_task(stop_task_id)
def get_new_task(self): for task in self.api.get_endless_stream('GetNewTask', api_proto.Task, api_proto.Empty()): task_msg = sly.json_loads(task.data) self.logger.debug('GET_NEW_TASK', extra={'task_msg': task_msg}) self.start_task(task_msg)