def getNextBatch(batch_num, batch_size, host, port, datapath): global sock if sock is None: initialize(host, port) sock.send_json( { "batch_num": batch_num, "batch_size": batch_size, "path": datapath, "keys": [ ("randompermpairs2", "images0"), ("randompermpairs2", "images1"), ("randompermpairs2", "actions"), ("randompermpairs2", "timediff"), ], } ) images = norml(recv_array(sock)) futures = norml(recv_array(sock)) actions = recv_array(sock) timediff = recv_array(sock) batch = {"current": images, "future": futures, "actions": actions, "timediff": timediff[:, np.newaxis]} return batch
def getNextBatch(batch_num, batch_size, host, port, datapath, keyname): global sock if sock is None: initialize(host, port) sock.send_json({'batch_num': batch_num, 'batch_size': batch_size, 'path': datapath, 'keys': [(keyname, 'images0'), (keyname, 'images1'), (keyname, 'actions'), (keyname, 'timediff')]}) images = recv_array(sock) futures = recv_array(sock) futurediffs = normalize(images.astype('float') - futures.astype('float')) images = norml(images) futurediffs = norml(futurediffs) actions = recv_array(sock) timediff = recv_array(sock) batch = {'current': images, 'future': futurediffs, 'actions': actions, 'timediff': timediff[:, np.newaxis] } return batch
def initialize(host, port, datapath, keyname): global ctx, sock, IMAGE_SIZE, NUM_CHANNELS, ACTION_LENGTH sock = ctx.socket(zmq.REQ) print("connecting...") sock.connect("tcp://%s:%d" % (host, port)) print("...connected") sock.send_json({'batch_size': 1, 'batch_num': 0, 'path': datapath, 'keys': [(keyname, 'images0'), (keyname, 'actions')] }) images = recv_array(sock) actions = recv_array(sock) IMAGE_SIZE = images.shape[1] NUM_CHANNELS = images.shape[-1] ACTION_LENGTH = actions.shape[1]
def initialize(host, port, datapath): global ctx, sock, NUM_OBJECTS, NUM_CHANNELS, IMAGE_SIZE sock = ctx.socket(zmq.REQ) print("connecting...") sock.connect("tcp://%s:%d" % (host, port)) print("...connected") sock.send_json({'batch_size': 1, 'batch_num': 0, 'path': datapath, 'keys': [('randomperm', 'images'), ('randomperm', \ 'objectcounts')] }) images = recv_array(sock) counts = recv_array(sock) NUM_CHANNELS = images.shape[-1] IMAGE_SIZE = images.shape[1] NUM_OBJECTS = counts.shape[1]
def receive_data(socket, type, cur_batch_num): """ Sends the data request to server and returns the received data. :param socket: ZMQ socket to access server :param request: request string :return: """ data = dict() if type == 'batch': request = make_req('batch', cur_batch_num) socket.send_json(request) data[KEYS[0]] = recv_array(socket) # Receive data data[KEYS[1]] = recv_array(socket) # Receive labels elif type == 'size': request = make_req('size', cur_batch_num) socket.send_json(request) data['size'] = recv_array(socket) # Receive data return data
def getNextBatch(batch_num, batch_size, host, port, datapath): global sock if sock is None: initialize(host, port) sock.send_json( { "batch_num": batch_num, "batch_size": batch_size, "path": datapath, "keys": [("randomperm", "images"), ("randomperm", "normals")], } ) images = norml(recv_array(sock)) normals = norml(recv_array(sock)) batch = {"images": images, "normals": normals} # images return batch
def getNextBatch(batch_num, batch_size, host, port, datapath): global sock if sock is None: initialize(host, port) sock.send_json({'batch_num': batch_num, 'batch_size': batch_size, 'path': datapath, 'keys': [('randomperm', 'images'), ('randomperm', 'objectcounts')]}) images = norml(recv_array(sock)) counts = recv_array(sock) objidvec = np.zeros((batch_size, counts.shape[1] + 1)).astype(np.float) objidvec[:, 1:] = counts noobj = objidvec.sum(1) == 0 objidvec[noobj, 0] = 1 objidvec = objidvec / objidvec.sum(1)[:, np.newaxis] batch = {'images': images, #images 'object_count_distributions': objidvec #object-id-present vector } return batch