def __init__(self, app_name, cfg): super(InferenceServer, self).__init__(app_name) self.inference_req = InferenceReq() self.classes = aisdk.common.other.make_synset( cfg['model_files']['labels.csv']) label_file = cfg['model_files']['labels.csv'] self.labels = parse_label_file(label_file) yaml_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resnet.yaml') update_config(yaml_file)
def create_net(configs): CTX.logger.info("load configs: %s", configs) # configs = json.loads(configs) tar_files_name='model_files' # load tar files if tar_files_name not in configs: return None, 400, 'no field tar_files' tar_files = configs[tar_files_name] conf, err = net.parse_infer_config(tar_files) if err: return None, 400, err params_file, sym_file, label_file = (conf.weight, conf.deploy_sym, conf.labels) use_device_name = 'use_device' if use_device_name not in configs: return None, 400, 'no field use_devices' use_device = configs[use_device_name] # threshold = 1e-3 thresholds = [] if 'custom_params' in configs: custom_values = configs['custom_params'] # if 'threshold' in custom_values: # threshold = custom_values['threshold'] if 'thresholds' in custom_values: thresholds = custom_values['thresholds'] else: thresholds = [1.0, 0.8, 0.8, 0.8, 0.7, 0.7, 1.0, 1.0, 1.0, 1.0, 1.0] ctx = [mx.gpu()] if use_device == 'GPU' else [mx.cpu()] classes = _make_synset(label_file) os.rename(sym_file, sym_file+'-symbol.json') os.rename(params_file, sym_file+'-0000.params') yaml_file = "/workspace/serving/python/evals/resnet.yaml" if os.path.isfile(yaml_file): update_config(yaml_file) else: return None, 400, 'No yaml files' predictor=get_net(config, ctx, sym_file, config.TEST.test_epoch, True) if predictor==None: return None, 400, 'fail to create predictor' return dict( error='', predictor=predictor, classes=classes, thresholds=thresholds), 0, ''
def net_init(): # configs = json.loads(config_str) # tar_files_name = 'tar_files' # # load tar files # if tar_files_name not in configs: # return dict(error='no field "tar_files"') # tar_files = configs[tar_files_name] # conf, err = net.parse_infer_config(tar_files) # if err: # return dict(error=err) # params_file, sym_file, label_file = (conf.weight, conf.deploy_sym, # conf.labels) # use_device_name = 'use_device' # if use_device_name not in configs: # return dict(error='no field "use_device"') # use_device = configs[use_device_name] sym_file = "/tmp/eval/init/old-1222/deploy.symbol.json" params_file = "/tmp/eval/init/old-1222/weight.params" label_file = "/tmp/eval/init/old-1222/labels.csv" use_device = "GPU" threshold = 1e-3 # thresholds = [0, 0.8, 0.8, 0.8, 0.7, 0.7, 1, 1, 1, 1, 1] thresholds = [0, 0.9, 0.8, 0.8, 1, 0.9, 0.9] # if 'custom_values' in configs: # custom_values = configs['custom_values'] # if 'threshold' in custom_values: # threshold = custom_values["threshold"] # if 'thresholds' in custom_values: # thresholds = custom_values['thresholds'] ctx = [mx.gpu()] if use_device == 'GPU' else [mx.cpu() ] # TODO set the gpu/cpu classes = _make_synset(label_file) os.rename(sym_file, sym_file + '-symbol.json') os.rename(params_file, sym_file + '-0000.params') update_config("/tmp/eval/init/old-1222/resnet.yaml") return dict(error='', predictor=get_net(config, ctx, sym_file, config.TEST.test_epoch, True), classes=classes, threshold=threshold, thresholds=thresholds)
def parse_args(): parser = argparse.ArgumentParser(description='Train R-FCN network') # general parser.add_argument( '--cfg', help='experiment configure file name', default= "../experiments/rfcn/cfgs/resnet_v1_101_imagenet_vid_rfcn_end2end_ohem.yaml", type=str) args, rest = parser.parse_known_args() # update config update_config(args.cfg) # training parser.add_argument('--frequent', help='frequency of logging', default=config.default.frequent, type=int) args = parser.parse_args() return args
def create_net(configs): CTX.logger.info("load configs: %s", configs) # configs = json.loads(configs) tar_files_name='model_files' # load tar files if tar_files_name not in configs: return None, 400, 'no field tar_files' tar_files = configs[tar_files_name] conf, err = net.parse_infer_config(tar_files) if err: return None, 400, err params_file, sym_file, label_file = (conf.weight, conf.deploy_sym, conf.labels) use_device_name = 'use_device' if use_device_name not in configs: return None, 400, 'no field use_devices' use_device = configs[use_device_name] ctx = [mx.gpu()] if use_device == 'GPU' else [mx.cpu()] labels = parse_label_file(label_file) os.rename(sym_file, sym_file+'-symbol.json') os.rename(params_file, sym_file+'-0000.params') yaml_file = "/workspace/serving/python/evals/resnet.yaml" if os.path.isfile(yaml_file): update_config(yaml_file) else: return None, 400, 'No yaml files' predictor=get_net(config, ctx, sym_file, config.TEST.test_epoch, True) if predictor==None: return None, 400, 'fail to create predictor' return dict( error='', predictor=predictor, labels=labels), 0, ''
def __init__(self, app_name, batch_size, lock, cfg): super(ForwardServer, self).__init__(app_name, batch_size) self.lock = lock use_device = cfg['use_device'] ctx = [mx.gpu()] if use_device == 'GPU' else [mx.cpu()] self.classes = aisdk.common.other.make_synset( cfg['model_files']['labels.csv']) sym_file = cfg['model_files']['deploy.symbol.json'] params_file = cfg['model_files']['weight.params'] _, arg_params, aux_params = aisdk.common.mxnet_utils.load_checkpoint( sym_file, params_file) arg_params, aux_params = load_param(arg_params, aux_params, process=True) yaml_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'resnet.yaml') update_config(yaml_file) self.predictor = get_net(config, ctx, arg_params, aux_params, True)
os.chdir('/home/tharun/Deformable-ConvNets/rfcn') print os.getcwd() sys.path.append( os.path.dirname(os.path.expanduser('~/Deformable-ConvNets/rfcn/symbols'))) sys.path.append( os.path.dirname(os.path.expanduser('~/Deformable-ConvNets/lib/utils'))) sys.path.append( os.path.dirname(os.path.expanduser('~/Deformable-ConvNets/rfcn'))) from rfcn.symbols import * from rfcn.config.config import config, update_config import cv2 import numpy as np import pprint update_config('transfer_config.yaml') def get_iterators(batch_size, data_shape=(3, 224, 224)): train = mx.io.ImageRecordIter(path_imgrec='''TODO''', data_name='data', label_name='softmax_label', batch_size=batch_size, data_shape=data_shape, shuffle=True, rand_crop=True, rand_mirror=True) val = mx.io.ImageRecordIter(path_imgrec='''TODO''', data_name='data', label_name='softmax_label', batch_size=batch_size,
def __init__(self, scales=(800, 1200), batch_size=1, dcn=True, softNMS=True, pretrained=True, model_dir=None, force_reload=False, gpu=0): os.environ['PYTHONUNBUFFERED'] = '1' os.environ['MXNET_CUDNN_AUTOTUNE_DEFAULT'] = '0' os.environ['MXNET_ENABLE_GPU_P2P'] = '0' import mxnet as mx from dcn.nms import gpu_nms_wrapper, cpu_softnms_wrapper, soft_nms from dcn.utils.load_model import load_param from rfcn.config.config import config, update_config from rfcn.core.tester import Predictor from rfcn.symbols import resnet_v1_101_rfcn from rfcn.symbols import resnet_v1_101_rfcn_dcn from rfcn.symbols import resnet_v1_101_rfcn_dcn_rpn from rfcn import CFGS cfg = CFGS / f"rfcn_coco_demo{softNMS and '_softNMS' or ''}.yaml" update_config(cfg) config.TEST.BATCH_IMAGES = batch_size config.symbol = 'resnet_v1_101_rfcn_dcn_rpn' if dcn else 'resnet_v1_101_rfcn' config.SCALES[0] = scales params, arg_params, aux_params = None, None, None if pretrained: epoch = softNMS and 8 or 0 params = dcn and 'rfcn_dcn_coco' or 'rfcn_coco' path = attempt_download(params, epoch=epoch, model_dir=model_dir, force=force_reload) arg_params, aux_params = load_param( f"{Path(path).parent / params}", epoch, process=True) instance = eval(config.symbol + '.' + config.symbol)() sym = instance.get_symbol(config, is_train=False) # Build the model predictor # BATCH_IMAGES Per GPU context self.config = config gpus = [gpu] if type(gpu) == int else gpu data_names = ['data', 'im_info'] label_names = [] data = self.preprocess() data = [[mx.nd.array(data[i][name]) for name in data_names] for i in range(len(data))] # [[data, im_info], ...] max_data_shape = [[('data', (1, 3, max([v[0] for v in config.SCALES]), max([v[1] for v in config.SCALES])))] ] # [[('data', (1, 3, 800, 1200))]] provide_data = [ [(k, v.shape) for k, v in zip(data_names, data[i])] for i in range(len(data)) ] # [[('data', (1, 3, h, w)), ('im_info', (h, w, scale))], ...]] provide_label = [None for i in range(len(data))] # [None, ...] self.predictor = Predictor(sym, data_names, label_names, context=[mx.gpu(gpu) for gpu in gpus], max_data_shapes=max_data_shape, provide_data=provide_data, provide_label=provide_label, arg_params=arg_params, aux_params=aux_params) self.data_names = data_names self.nms = gpu_nms_wrapper(config.TEST.NMS, 0) # 0.2 for SNMS and 0.3 otherwise if softNMS: self.snms = cpu_softnms_wrapper()