Beispiel #1
0
    def test_should_return_all_frames_when_no_predicate_is_applied(self):
        frame_1 = Frame(1, np.ones((1, 1)), None)
        frame_2 = Frame(1, 2 * np.ones((1, 1)), None)
        frame_3 = Frame(1, 3 * np.ones((1, 1)), None)
        outcome_1 = Prediction(frame_1, ["car", "bus"], [0.5, 0.6])
        outcome_2 = Prediction(frame_2, ["bus"], [0.5, 0.6])
        outcome_3 = Prediction(frame_3, ["car", "train"], [0.5, 0.6])
        batch = FrameBatch(
            frames=[
                frame_1,
                frame_2,
                frame_3,
            ],
            info=None,
            outcomes={"test": [outcome_1, outcome_2, outcome_3]})

        plan = type("ScanPlan", (), {"predicate": None})
        predicate_executor = SequentialScanExecutor(plan)
        predicate_executor.append_child(DummyExecutor([batch]))

        expected = FrameBatch(
            frames=[frame_1, frame_2, frame_3],
            info=None,
            outcomes={"test": [outcome_1, outcome_2, outcome_3]})
        filtered = list(predicate_executor.next())[0]
        self.assertEqual(expected, filtered)
Beispiel #2
0
    def test_should_return_only_frames_satisfy_predicate(self):
        frame_1 = Frame(1, np.ones((1, 1)), None)
        frame_2 = Frame(1, 2 * np.ones((1, 1)), None)
        frame_3 = Frame(1, 3 * np.ones((1, 1)), None)
        outcome_1 = Prediction(frame_1, ["car", "bus"], [0.5, 0.6])
        outcome_2 = Prediction(frame_2, ["bus"], [0.5, 0.6])
        outcome_3 = Prediction(frame_3, ["car", "train"], [0.5, 0.6])
        batch = FrameBatch(
            frames=[
                frame_1,
                frame_2,
                frame_3,
            ],
            info=None,
            outcomes={"test": [outcome_1, outcome_2, outcome_3]})
        expression = type("AbstractExpression", (),
                          {"evaluate": lambda x: [False, False, True]})

        plan = type("ScanPlan", (), {"predicate": expression})
        predicate_executor = SequentialScanExecutor(plan)
        predicate_executor.append_child(DummyExecutor([batch]))

        expected = FrameBatch(frames=[frame_3],
                              info=None,
                              outcomes={"test": [outcome_3]})
        filtered = list(predicate_executor.next())[0]
        self.assertEqual(expected, filtered)
Beispiel #3
0
 def test_should_return_list_of_predictions_for_each_frame_in_batch(self):
     batch = FrameBatch(frames=[Frame(1, np.ones((1, 1)), None)], info=None)
     predictions = [['A', 'B']]
     scores = [[1, 1]]
     expected = [Prediction(batch.frames[0], predictions[0], scores[0])]
     actual = Prediction.predictions_from_batch_and_lists(
         batch, predictions, scores)
     self.assertEqual(expected, actual)
Beispiel #4
0
    def test_func_expr_with_cmpr_and_const_expr_should_work(self):
        frame_1 = Frame(1, np.ones((1, 1)), None)
        frame_2 = Frame(1, 2 * np.ones((1, 1)), None)
        outcome_1 = Prediction(frame_1, ["car", "bus"], [0.5, 0.6])
        outcome_2 = Prediction(frame_1, ["bus"], [0.6])

        func = FunctionExpression(lambda x: [outcome_1, outcome_2])
        value_expr = ConstantValueExpression("car")
        expression_tree = ComparisonExpression(ExpressionType.COMPARE_EQUAL,
                                               func, value_expr)

        batch = FrameBatch(frames=[frame_1, frame_2])

        self.assertEqual([True, False], expression_tree.evaluate(batch))
    def test_should_return_all_frames_when_no_predicate_is_applied(self):
        dataframe = create_dataframe(3)

        outcome_1 = Prediction(dataframe.iloc[0], ["car", "bus"], [0.5, 0.6])
        outcome_2 = Prediction(dataframe.iloc[1], ["bus"], [0.5, 0.6])
        outcome_3 = Prediction(dataframe.iloc[2], ["car", "train"], [0.5, 0.6])
        batch = FrameBatch(
            frames=dataframe,
            outcomes={"test": [outcome_1, outcome_2, outcome_3]})

        plan = type("ScanPlan", (), {"predicate": None})
        predicate_executor = SequentialScanExecutor(plan)
        predicate_executor.append_child(DummyExecutor([batch]))

        filtered = list(predicate_executor.exec())[0]
        self.assertEqual(batch, filtered)
 def classify(self, batch: FrameBatch) -> List[Prediction]:
     frames = batch.frames_as_numpy_array()
     (pred_classes, pred_scores, pred_boxes) = self._get_predictions(frames)
     return Prediction.predictions_from_batch_and_lists(batch,
             pred_classes,
             pred_scores, 
             boxes=pred_boxes)
Beispiel #7
0
 def test_should_check_if_batch_frames_equivalent_to_number_of_scores(self):
     batch = FrameBatch(frames=[Frame(1, np.ones((1, 1)), None)], info=None)
     predictions = [['A', 'B']]
     scores = []
     self.assertRaises(
         AssertionError,
         lambda x=None: Prediction.predictions_from_batch_and_lists(
             batch, predictions, scores))
    def test_should_return_only_frames_satisfy_predicate(self):
        dataframe = create_dataframe(3)

        outcome_1 = Prediction(dataframe.iloc[0], ["car", "bus"], [0.5, 0.6])
        outcome_2 = Prediction(dataframe.iloc[1], ["bus"], [0.5, 0.6])
        outcome_3 = Prediction(dataframe.iloc[2], ["car", "train"], [0.5, 0.6])
        batch = FrameBatch(
            frames=dataframe,
            outcomes={"test": [outcome_1, outcome_2, outcome_3]})
        expression = type("AbstractExpression", (),
                          {"evaluate": lambda x: [False, False, True]})

        plan = type("ScanPlan", (), {"predicate": expression})
        predicate_executor = SequentialScanExecutor(plan)
        predicate_executor.append_child(DummyExecutor([batch]))

        expected = batch[[2]]
        filtered = list(predicate_executor.exec())[0]
        self.assertEqual(expected, filtered)
Beispiel #9
0
 def test_should_check_if_batch_frames_equivalent_to_no_of_boxes_if_given(
         self):
     batch = Batch(frames=[Frame(1, np.ones((1, 1)), None)])
     predictions = [['A', 'B']]
     scores = [[1, 1]]
     boxes = []
     self.assertRaises(
         AssertionError,
         lambda x=None: Prediction.predictions_from_batch_and_lists(
             batch, predictions, scores, boxes=boxes))
Beispiel #10
0
    def test_aggregation_min(self):
        columnName = TupleValueExpression(0)
        aggr_expr = AggregationExpression(
            ExpressionType.AGGREGATION_MIN,
            None,
            columnName
        )

        frame_1 = Frame(1, np.ones((1, 1)), None)
        frame_2 = Frame(2, 2 * np.ones((1, 1)), None)
        frame_3 = Frame(3, 3 * np.ones((1, 1)), None)
        outcome_1 = Prediction(frame_1, ["car", "bus"], [0.5, 0.6])
        outcome_2 = Prediction(frame_2, ["bus"], [0.5, 0.6])
        outcome_3 = Prediction(frame_3, ["car", "train"], [0.5, 0.6])
        input_batch = FrameBatch(frames=[
            frame_1,
            frame_2,
            frame_3,
        ], info=None)

        expected_value = 1
        output_value  = aggr_expr.evaluate(input_batch)
        self.assertEqual(expected_value, output_value)