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)
image = size_image(image) plt2d=None plt3d=None try: #if True: pose_2d, visibility, pose_3d = pose_estimator.estimate(image) if 'display' in args: plt3d,plt2d=display_results(image, pose_2d, visibility, pose_3d) lift={} lift["pose2d"]=pose_2d.round(2).tolist() lift["pose3d"]=pose_3d.round(2).tolist() lift["visibility"]=visibility.tolist() #cv2.imshow('req',plt3d) #cv2.waitKey(0) zmqa.send(socket,plt3d,extra=lift) except: #else: print "!@*!! error:", sys.exc_info()[0] lift={} lift['error']=str(sys.exc_info()[0]) lift['fname']=fname zmqa.send(socket,None,extra=lift) # close model pose_estimator.close()
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()
# # Hello World server in Python # Binds REP socket to tcp://*:5555 # Expects b"Hello" from client, replies with b"World" # import time import zmq import cv2 import numpy as np import zmqnparray as zmqa context = zmq.Context() socket = context.socket(zmq.REP) socket.bind("tcp://*:5555") while True: # Wait for next request from client A, extra = zmqa.recv(socket) if 'fname' in extra: print("Received request %s" % extra['fname']) else: print("Received request %s" % extra) # Do some 'work' #time.sleep(1) B = cv2.Canny(A, 100, 200) nonzero = cv2.countNonZero(B) # Send reply back to client zmqa.send(socket, B, extra=nonzero)
# Connects REQ socket to tcp://localhost:5555 # Sends "Hello" to server, expects "World" back # import zmq import cv2 import numpy as np import zmqnparray as zmqa context = zmq.Context() # Socket to talk to 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=cv2.imread('concombre.png',1) print("Sending request %s … " % (request) ) cv2.imshow('request',A) zmqa.send(socket,A,extra=None) # Get the reply. B,extra= zmqa.recv(socket) print("[%s] Received reply %s" % (request,str(extra))) if B is not None: cv2.imshow('reply',B) cv2.waitKey(0) 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)))
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Hello World server in Python # Binds REP socket to tcp://*:5555 # Expects b"Hello" from client, replies with b"World" # import time import zmq import numpy as np import zmqnparray as zmqa context = zmq.Context() socket = context.socket(zmq.REP) socket.bind("tcp://*:5555") while True: # Wait for next request from client A = zmqa.recv(socket) print("Received request: %s" % str(A)) # Do some 'work' time.sleep(1) B = A[:] + 1 # Send reply back to client zmqa.send(socket, B)