def main(args): logger = logging.getLogger(__name__) merge_cfg_from_file(args.cfg) cfg.NUM_GPUS = 1 args.weights = cache_url(args.weights, cfg.DOWNLOAD_CACHE) assert_and_infer_cfg(cache_urls=False) assert not cfg.MODEL.RPN_ONLY, \ 'RPN models are not supported' assert not cfg.TEST.PRECOMPUTED_PROPOSALS, \ 'Models that require precomputed proposals are not supported' model = infer_engine.initialize_model_from_cfg(args.weights) dummy_coco_dataset = dummy_datasets.get_coco_dataset() logger.info( ' \ Note: inference on the first image will be slower than the ' 'rest (caches and auto-tuning need to warm up)' ) while True: reply = {} # Wait for next request from client im,extra = zmqa.recv(socket) if extra is not None and 'fname' in extra: print("Received request %s" % extra) reply['fname']=extra['fname'] else: print("Received request %s" % extra) reply['fname'] = 'input.jpg' # set file name im_name=reply['fname'] timers = defaultdict(Timer) t = time.time() with c2_utils.NamedCudaScope(0): cls_boxes, cls_segms, cls_keyps = infer_engine.im_detect_all( model, im, None, timers=timers ) logger.info('Inference time: {:.3f}s'.format(time.time() - t)) for k, v in timers.items(): logger.info(' | {}: {:.3f}s'.format(k, v.average_time)) out_name = os.path.join( args.output_dir, '{}'.format(os.path.basename(im_name) + '.' + args.output_ext) ) masks=do_one_image_opencv( im, # BGR -> RGB for visualization cls_boxes, cls_segms, cls_keyps, thresh=0.7, reply=reply ) zmqa.send(socket, masks,extra=reply)
INPUT_SIZE = 368 image_size = np.array((INPUT_SIZE,INPUT_SIZE, 3)).astype(np.int32) # create pose estimator pose_estimator = PoseEstimator(image_size, SESSION_PATH, PROB_MODEL_PATH) # load model pose_estimator.initialise() plt2d=None plt3d=None while True: plt2d=None plt3d=None # Wait for next request from client image, extra = zmqa.recv(socket) fname="" if extra is not None and 'fname' in extra: fname=extra['fname'] print("[%s]" % fname) else: print(".") #cv2.imshow('req',image) #cv2.waitKey(0) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # conversion to rgb image = size_image(image) plt2d=None plt3d=None try: #if True:
file_list = arguments.pop("<files>", None) context = zmq.Context() # Socket to talk to server socket = context.socket(zmq.REQ) socket.connect("tcp://localhost:5555") for fname in file_list: if os.path.isfile(fname) and os.access(fname, os.R_OK): A = cv2.imread(fname, 1) if A is None: print("[%s] Could not read image" % (fname)) else: arguments['fname'] = fname print("[%s] Sending request… " % (fname)) zmqa.send(socket, A, extra=arguments) #zmqa.send(socket,A) # Get the reply. B, extra = zmqa.recv(socket) print("[%s] Received reply %s" % (fname, str(extra))) cv2.imshow('request', A) if B is not None: cv2.imshow('reply', B) cv2.waitKey(10) else: print("[%s] could not access file" % (fname)) cv2.destroyAllWindows()
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Hello World client in Python # Connects REQ socket to tcp://localhost:5555 # Sends "Hello" to server, expects "World" back # import zmq import numpy as np import zmqnparray as zmqa context = zmq.Context() # Socket to talk to server print("Connecting to hello world server…") socket = context.socket(zmq.REQ) socket.connect("tcp://localhost:5555") # Do 10 requests, waiting each time for a response for request in range(10): A = np.random.rand(3, 2, 5) #print("Sending request %s … %s" % (request,str(A)) ) print("Sending request %s … %s" % (request, A)) zmqa.send(socket, A) # Get the reply. B = zmqa.recv(socket) print("Received reply %s [ %s ]" % (request, str(B)))