Example #1
0
 def createSocket(self):
     self.identity = utils.identity()
     logger.debug('NEW IDENTITY: %s ' % self.identity)
     self.worker = self.ctx.socket(zmq.XREQ)
     self.worker.setsockopt(zmq.IDENTITY, self.identity)
     self.worker.connect('tcp://%s' % CONFIG['ROUTER'])
     self.worker.send('READY')
Example #2
0
    def forward(self, x):
        """Forwardpropagation pass"""

        # Layer_in
        a_in = np.matmul(x, self.w_in.T) + self.b_in
        z_in = relu(a_in)
        # Layer_rec
        a_rec = np.matmul(z_in, self.w_rec.T) + self.b_rec
        z_rec = relu(a_rec)
        # Layer_link
        a_link = np.matmul(np.matmul(x, self.w_reduce), self.w_link.T)
        z_link = identity(a_link)
        # Layer_out
        a_out = np.matmul(z_rec+z_link, self.w_out.T) + self.b_out
        y = relu(a_out)

        # Set internal state
        self._state.update({
            'x': x,
            'y': y,
            'a_out': a_out,
            'z_link': z_link,
            'a_link': a_link,
            'z_rec': z_rec,
            'a_rec': a_rec,
            'z_in': z_in,
            'a_in': a_in,
        })

        return y
def segment_cells(image, max_cell_size):
    """Return segmented cells."""
    image = identity(image)

    wall = threshold_adaptive_median(image, block_size=101)
    seeds = remove_small_objects(wall, min_size=100)
    seeds = dilate_binary(seeds)
    seeds = invert(seeds)
    seeds = remove_small_objects(seeds, min_size=5)
    seeds = connected_components(seeds, background=0)

    segmentation = watershed_with_seeds(-image, seeds=seeds)
    segmentation = remove_large_segments(segmentation, max_cell_size)
    return segmentation, wall
Example #4
0
def main():
    parser = argparse.ArgumentParser(
        description='Adopt pairwise aligner to generate identity matrix')
    parser.add_argument('fasta_path',
                        type=str,
                        help='the path of fasta files to parse')
    parser.add_argument('out_path', type=str, help='output dir')
    args = parser.parse_args([
        '/home/ZwZ/database/M/linsi/M1_M2_unique.fasta',
        '/home/ZwZ/database/M/linsi/M1_M2_unique.npy'
    ])

    fasta = read_fasta(args.fasta_path)

    identity_M = identity(fasta)

    np.save(args.out_path, identity_M)
Example #5
0
    def __init__(self):

        self.router = None
        self.stats = None
        self.storage = CONFIG['STORAGE']
        self.cameras = {}
        self.current = collections.defaultdict(list)
        self.inprocessing = 0
        self.processing_speed = 0
        self.limiter = 0
        self.bufferlen = CONFIG['BUFFERLEN']
        self.context = zmq.Context.instance()
        self.loop = ioloop.IOLoop.instance()

        camera_address = CONFIG['CAMERA_ADDRESS'] 
        camera_port = CONFIG['CAMERA_PORT']
        router_address = CONFIG['ROUTER']
        stats_address = CONFIG['STATS']
        presenter_address = CONFIG['PRESENTER']
        graph_address = CONFIG['GRAPH']

        self.processing_buffer = collections.deque()
        self.timestamp_old = 0

        self._camera = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        self._camera.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self._camera.setblocking(0)
        self._camera.bind((camera_address, camera_port))
        self._camera.listen(10)
        self.loop.add_handler(self._camera.fileno(), self.cameraConnection, self.loop.READ)

        #if 'tracker-router.idt' in os.listdir('.'):                 
        #    with open('tracker-router.idt', 'r') as f:
        #        self.router_identity = f.read()
        #else:
        #    self.router_identity = 'router-%s' % utils.identity()
        #    with open('tracker-router.idt', 'w') as f:
        #        f.write(self.router_identity)

        self.router_identity = 'router-%s' % utils.identity()
        logger.debug('ROUTER IDENTITY: %s' % self.router_identity)

        self._router = self.context.socket(zmq.XREQ)
        self._router.setsockopt(zmq.IDENTITY, self.router_identity)
        self._router.connect('tcp://%s' % router_address)
        self.router = zmqstream.ZMQStream(self._router, self.loop)
        self.router.on_recv(self.routerReceive)
        
        self.stats_identity = 'stats-%s' % utils.identity()
        logger.debug('STATS IDENTITY: %s' % self.stats_identity)

        self._stats = self.context.socket(zmq.PUB)
        self._stats.setsockopt(zmq.IDENTITY, self.stats_identity)
        self._stats.bind('tcp://%s' % stats_address)
        self.stats = zmqstream.ZMQStream(self._stats, self.loop)
        
        self.presenter_identity = 'presenter-%s' % utils.identity()
        logger.debug('PRESENTER IDENTITY: %s' % self.presenter_identity)
        
        self._presenter = self.context.socket(zmq.PUB)
        self._presenter.setsockopt(zmq.IDENTITY, self.presenter_identity)
        self._presenter.bind('tcp://%s' % presenter_address)
        self.presenter = zmqstream.ZMQStream(self._presenter, self.loop)

        self.graph_identity = 'graph-%s' % utils.identity()
        logger.debug('GRAPH IDENTITY: %s' % self.graph_identity)
        
        self._graph = self.context.socket(zmq.PUB)
        self._graph.setsockopt(zmq.IDENTITY, self.graph_identity)
        self._graph.bind('tcp://%s' % graph_address)
        self.graph = zmqstream.ZMQStream(self._graph, self.loop)
Example #6
0
    def __init__(self):

        ctx = zmq.Context()
        
        backend_identity = 'backend-%s' % utils.identity()
        frontend_identity = 'frontend-%s' % utils.identity()
        logger.debug('BACKEND: %s ' % backend_identity)
        logger.debug('FRONTEND: %s' % frontend_identity)

        frontend = ctx.socket(zmq.XREP)
        frontend.setsockopt(zmq.IDENTITY, frontend_identity)
        frontend.bind('tcp://%s' % CONFIG['FRONTEND'])

        backend  = ctx.socket(zmq.XREP)
        backend.setsockopt(zmq.IDENTITY, backend_identity)
        backend.bind('tcp://%s' % CONFIG['BACKEND'])

        worker_queue = collections.deque()
        self.worker_all = 0
        heartbeat = time.time() + CONFIG['HEART_INTER']

        poller = zmq.Poller()
        poller.register(frontend, zmq.POLLIN)
        poller.register(backend, zmq.POLLIN)

        while True:
            socks = dict(poller.poll())
            worker_queue = self.workerFlush(worker_queue)

            if backend in socks:
                message = backend.recv_multipart()
                worker = message[0]

                if len(message) == 2:
                    action  = message[1]
                    if action == 'READY':
                        self.workerDelete(worker, worker_queue)
                        self.workerAppend(worker, worker_queue)
                    elif action == 'HEARTBEAT':
                        self.workerRefresh(worker, worker_queue)
                    else:
                        logger.debug('INVALID MESSAGE BACKEND')
                else:
                    self.workerAppend(worker, worker_queue)
                    frontend.send_multipart(message[1:])

            if len(worker_queue):
                if frontend in socks:
                    received = frontend.recv_multipart()
                    expire = worker_queue.pop()
                    destination = worker_queue.pop()
                    message = [destination]
                    message.extend(received)
                    #message.extend(str(self.worker_all))
                    backend.send_multipart(message)

            if time.time() > heartbeat:
                for n, w in enumerate(worker_queue):
                    if n % 2 == 0:
                        backend.send_multipart([w, 'HEARTBEAT'])
                heartbeat = time.time() + CONFIG['HEART_INTER']


        backend.close()
        frontend.close()
        ctx.term()