def publish(self, envelope):
     try:
         msg = Message(body=binary_serialize(envelope))
         self._bus.send_topic_message(self.topic_name, msg)
     except AzureHttpError, ef:
         logger.error('''Exception sending coordinates to HITL:
             %s for url %s and container %''', ef, envelope.url, envelope.container)
         raise
    def listen(self):
        self._message = self._bus.receive_subscription_message(self.topic_name, self.subscription)
        if self._message is not None and self._message.body is not None:
            SB_IO_COUNTER.labels(direction='inbound',
                                 kind=self._kind).inc()
            try:
                envelope = self._deserialize()
                logger.info(
                    "Ingested Envelope with correlation id {cid}".format(
                        cid=envelope.correlation_id))
                return envelope
            except EOFError, ef:
                logger.error("Poison message received: %s", ef)
                self._bus.delete_subscription_message(self._message)

            return None
Exemple #3
0
    def _retry(self, f):

        count = 0
        while True:
            try:

                return f()
            except AuthenticationError, ae:
                logger.error("Unrecoverable Authentication Exception")
                raise ae
            except (ConnectionError, TimeoutError), re:
                count += 1
                if count < self._max_retries:
                    logger.warn("Transient Error Received %s ", re)
                    time.sleep(self._retry_period)
                else:
                    logger.error("Unrecoverable Network Error %s", re)
                    raise re
Exemple #4
0
    def _workflow(self):
        self._pano_event_envelope = self._subscriber.listen()
        if self._pano_event_envelope is not None:

            if self._pano_event_envelope.pano_upload is not None:
                PANO_INGEST_COUNTER.labels(direction='inbound').inc()
                try:

                    logger.info(
                        "Ingested PanoEventEnvelope with correlation id {cid}".format(
                            cid=self._pano_event_envelope.correlation_id))
                    return self.pano_service.download(self._pano_event_envelope.pano_upload)
                except EOFError, ef:
                    logger.error("Poison message received: %s", ef)
                    self._subscriber.acknowledge()

            else:
                logger.warn("Irrelevant envelope with correlation id {cid}".format(
                    cid=self._pano_event_envelope.correlation_id))
                self._subscriber.acknowledge()
Exemple #5
0
    def consume_n(self, n=100):

        count = 0
        while count < n:
            envelope = self._client.listen()
            if envelope is not None:
                count += 1
                batch = envelope.label_detected_batch
                if batch is not None:
                    try:
                        self._redis_storage.push(batch)
                    except AzureException, aze:
                        logger.error(
                            "Unable to store AisleCompletionEventEntity %s",
                            aze)
                    else:
                        logger.info("Stored LabelDetectedBatch")
                        self._client.acknowledge()
                        envelope = None
                else:
                    self._client.acknowledge()
            else:
                return
Exemple #6
0
 def provide(self):
     if self._pano_event_envelope is not None:
         logger.error("Requested to provide pano while pano is outstanding")
     return self._workflow()
Exemple #7
0
    def run(self):
        try:
            # get pano byte_array and pano upload event
            self.azure_pano_byte_response = self.provider.provide(return_panos)
            if self.azure_pano_byte_response is not None:
                # chunk the images
                self.chunk_image.byte_array = \
                    self.azure_pano_byte_response.byte_array
                self.pano_upload_event =  \
                    self.azure_pano_byte_response.pano_upload_event

                self.chunk_image.pano_upload_event = self.pano_upload_event
                self.positions, self.tf_call_service.img = self.chunk_image.run()

                # tensorflow service call
                self.tf_call_service.pano_upload_event = self.pano_upload_event
                self.coordinates = self.tf_call_service.run(
                                    stride_info=TF.config('OOS_STRIDE_INFO'),
                                    height=TF.config('OOS_HEIGHT'),
                                    width=TF.config('OOS_WIDTH'),
                                    positions=self.positions)

                # appy coordinate correction
                self.apply_coordinate_correction.positions_rect_dict = \
                    self.coordinates
                self.apply_coordinate_correction.pano_upload_event = \
                    self.pano_upload_event
                self.coordinates = self.apply_coordinate_correction.run()

                # filter merge boxes
                self.filter_merge_boxes.rects = self.coordinates
                self.filter_merge_boxes.pano_upload_event = \
                    self.pano_upload_event
                print 'filter_merge_boxes_rect = ', self.filter_merge_boxes.rects
                self.oos_coordinates = self.filter_merge_boxes.run()

                # get label coordinates
                self.label_coordinates = self.label_service.request_labels(
                    self.pano_upload_event.header.customer_id,
                    self.pano_upload_event.header.store_id,
                    self.pano_upload_event.header.run_id,
                    self.pano_upload_event.header.aisle_id)

                # post processing

                self.post_processing.oos_coords = self.oos_coordinates
                self.post_processing.label_coords = self.label_coordinates
                self.post_processing.pano_upload_event = self.pano_upload_event
                self.coordinates = self.post_processing.run()
                # send coordinates to HITL
                out_rec_event = OutRecommendationEvent(
                    header=self.azure_pano_byte_response.pano_upload_event.header,
                    url=self.azure_pano_byte_response.pano_upload_event.url,
                    container_name=self.azure_pano_byte_response.pano_upload_event.container_name,
                    detected_outs=self.coordinates['detection_boxes']
                    )

                self.coordinate_storage.store(out_rec_event)

                # acknowledge pano has been processed
                self.provider.acknowledge()

                TF_SUCCESS_COUNT.inc()
                return self.coordinates
        except AzureException, ae:
            # TODO more specific errors for transient exceptions
            TF_FAILURE_COUNT.inc()
            logger.error("Azure Exception ", exc_info=True)
Exemple #8
0
                # acknowledge pano has been processed
                self.provider.acknowledge()

                TF_SUCCESS_COUNT.inc()
                return self.coordinates
        except AzureException, ae:
            # TODO more specific errors for transient exceptions
            TF_FAILURE_COUNT.inc()
            logger.error("Azure Exception ", exc_info=True)
        except tf.OpError, oe:
            TF_FAILURE_COUNT.inc()
            logger.error("Tensorflow Exception", exc_info=True)
        except WorkflowException, we:
            TF_FAILURE_COUNT.inc()
            logger.error("Workflow Exception {0}".format(we), exc_info=True)
        except Exception, e:
            TF_FAILURE_COUNT.inc()
            logger.info("pano not processed", exc_info=True)

        return None


def return_panos(byte_array):
    # TODO need to write a iterator to deliver a pano
    return byte_array


def load_graph(trained_model_env):
    ''' This method loads the graph '''
    dir_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),