Ejemplo n.º 1
0
 def test_workflow_exception_when_tensor_flow_inference_call_fails(self):
     self.mock_tf_call_service.run.side_effect = WorkflowException()
     self.workflow = WorkFlow(self.graph, self.chunk_image,
                              self.mock_tf_call_service,
                              self.mock_apply_coordinate_correction, None,
                              None, None, None, self.provider)
     self.workflow.run()
     self.workflow.apply_coordinate_correction.run.assert_not_called()
Ejemplo n.º 2
0
 def test_workflow_exception_when_chunk_fails(self):
     self.mock_chunk_image.run.side_effect = WorkflowException()
     self.tf_call_service = mock.MagicMock(TfCall())
     self.workflow = WorkFlow(self.graph, self.mock_chunk_image,
                              self.tf_call_service, None, None, None, None,
                              None, self.provider)
     self.workflow.run()
     self.workflow.tf_call_service.run.assert_not_called()
Ejemplo n.º 3
0
 def test_workflow_exception_when_post_processing_fails(self):
     self.mock_tf_call_service.run.return_value = \
         {(1536, 8192):
          [Rect(562, 954, 665, 111, 0.3364628255367279)]}
     self.mock_post_processing.run.side_effect = WorkflowException()
     self.workflow = WorkFlow(
         self.graph, self.chunk_image, self.mock_tf_call_service,
         self.apply_coordinate_correction, self.filter_merge_boxes,
         self.mock_label_service, self.mock_coordinate_storage,
         self.mock_post_processing, self.provider)
     self.workflow.run()
     self.workflow.provider.acknowledge.assert_not_called()
Ejemplo n.º 4
0
 def run(self):
     try:
         img = cv2.imdecode(self.byte_array, cv2.IMREAD_UNCHANGED)
         start_x, start_y = 0, 0
         end_y, end_x, _ = img.shape
         positions = self.get_pano_positions(
             start_x, start_y, end_y, end_x,
             TFCONST.config('OOS_STRIDE_INFO')['height'],
             TFCONST.config('OOS_STRIDE_INFO')['width'],
             TFCONST.config('OOS_STRIDE_INFO')['h_stride'],
             TFCONST.config('OOS_STRIDE_INFO')['w_stride'])
     except Exception as e:
         raise WorkflowException(
             'Image Chunking Exception in ' +
             'line {0} for container {1} and url {2}'.format(
                 sys.exc_info()[2].tb_lineno,
                 self.pano_upload_event.container_name,
                 self.pano_upload_event.url), e)
     return positions, img
Ejemplo n.º 5
0
    def run(self):
        try:
            all_rects = []
            for position, rects in self.positions_rect_dict.items():
                i, j = position
                for rect in rects:
                    rect.transform(self.resize_factor, j, i)
                    all_rects.append(rect)

                logDebug(
                    "rects after coordinate correction {0} ".format(all_rects))

        except Exception as e:
            raise WorkflowException(
                'Coordinate Correction Exception in ' +
                'line {0} for container {1} and url {2}'.format(
                    sys.exc_info()[2].tb_lineno,
                    self.pano_upload_event.container_name,
                    self.pano_upload_event.url), e)

        return all_rects
Ejemplo n.º 6
0
    def run(self):
        ''' This method filters and merge the boxes '''
        try:
            final_indices = {}
            final_rects = sorted(self.rects,
                                 key=lambda r: r.width * r.height,
                                 reverse=True)
            for i in range(len(final_rects)):

                if i in final_indices:
                    curr_root = final_indices[i]
                else:
                    curr_root = i
                rect = final_rects[curr_root]

                for j in range(i + 1, len(final_rects)):
                    if j in final_indices:
                        other = final_rects[final_indices[j]]
                    else:
                        other = final_rects[j]

                    cov = other.cov(rect)
                    if cov > TFCONST.config('OOS_ARGS')['iou_threshold']:
                        final_indices[j] = curr_root
            final_rects = list(
                set([
                    final_rects[i] if i not in final_indices else
                    final_rects[final_indices[i]]
                    for i in range(len(final_rects))
                ]))
        except Exception as e:
            raise WorkflowException(
                'Filter Merge Boxes Exception in ' +
                'line {0} for container {1} and url {2}'.format(
                    sys.exc_info()[2].tb_lineno,
                    self.pano_upload_event.container_name,
                    self.pano_upload_event.url), e)
        return final_rects
Ejemplo n.º 7
0
    def run(self):
        try:
            oos_coords_input = reformat_oos_coords_to_x_y_axis(self.oos_coords)
            label_coords_input = reformat_label_coords_to_x_y_axis(
                self.label_coords)

            logDebug('oos coordinates before pre processing = {0} {1}'.format(
                oos_coords_input, self._add_container_n_url_name()))

            logDebug(
                'label coordinates before pre processing = {0} {1}'.format(
                    label_coords_input, self._add_container_n_url_name()))

            oos_rects = read_boxes(oos_coords_input)

            label_rects = read_boxes(label_coords_input)

            oos_rects = [r for r in oos_rects if r.score > self.min_conf]

            oos_rects = filter_boxes_by_size(oos_rects,
                                             min_w=150,
                                             min_h=80,
                                             max_asp_ratio=12)

            label_rects = filter_boxes_by_size(label_rects, min_w=40, min_h=20)

            if len(label_rects) == 0:
                return {
                    'oos_coordinates': format_coords_output(oos_rects),
                    'label_coordinates': None,
                    'detection_boxes':
                    filter_oos_by_labels(oos_rects, label_rects)
                }

            shelf_rects = read_boxes(extract_shelves(label_rects))

            logInfo('no of oos before processing with shelves {0} {1}'.format(
                len(oos_rects), self._add_container_n_url_name()))

            oos_rects, removed_rects = filter_boxes_by_shelves(
                oos_rects, shelf_rects)

            logInfo('no of oos within shelf = {0} {1}'.format(
                len(oos_rects), self._add_container_n_url_name()))

            logInfo('no of labels = {0} {1}'.format(
                len(label_rects), self._add_container_n_url_name()))

            # add labels that is part of oos regions.
            detection_boxes = filter_oos_by_labels(oos_rects, label_rects)

            logInfo('no of labels within oos region = {0} {1} '.format(
                len(label_rects), self._add_container_n_url_name()))

            # This can removed - Added for debugging.
            oos_coordinates = format_coords_output(
                detection_boxes.oos_coordinates)
            label_coordinates = format_coords_output(
                detection_boxes.label_coordinates)

            logDebug('final shelf coordinates = {0} {1}'.format(
                shelf_rects, self._add_container_n_url_name()))

            logDebug('final oos coordinates = {0} {1}'.format(
                oos_coordinates, self._add_container_n_url_name()))

            logDebug('final label coordinates = {0} {1} '.format(
                label_coordinates, self._add_container_n_url_name()))

        except Exception as e:
            raise WorkflowException(
                'Post Process Exception in ' +
                'line {0} for container {1} and url {2}'.format(
                    sys.exc_info()[2].tb_lineno,
                    self.pano_upload_event.container_name,
                    self.pano_upload_event.url), e)

        return {
            'detection_boxes': detection_boxes,
            'oos_coordinates': oos_coordinates,
            'label_coordinates': label_coordinates
        }