Ejemplo n.º 1
0
def test_feature_detection_labelling_concise():
    """Test `feature_detection_labelling` function in `generator` module by considering a concise
    labelling, *i.e.* all labels are represented into the array:
    * as a preliminary verification, check if passing string labels raises an AttributeError
    exception
    * test if output shape is first input shape (batch size) + an additional dimension given by the
    `label_ids` length
    * test if both representation provides the same information (native array on the first hand and
    its one-hot version on the second hand)
    """
    a = np.array([[[[10, 10, 200], [10, 10, 200], [10, 10, 200]],
                   [[200, 200, 200], [200, 200, 200], [10, 10, 200]],
                   [[200, 200, 200], [200, 200, 200], [200, 200, 200]]],
                  [[[10, 200, 10], [10, 200, 10], [10, 10, 200]],
                   [[200, 10, 10], [10, 200, 10], [10, 10, 200]],
                   [[10, 200, 10], [200, 10, 10], [10, 10, 200]]]])
    labels = np.unique(a.reshape(-1, 3), axis=0).tolist()
    wrong_config = [{
        'id': '0',
        'color': [10, 10, 200],
        'is_evaluate': True
    }, {
        'id': '1',
        'color': [200, 10, 10],
        'is_evaluate': True
    }, {
        'id': '2',
        'color': [10, 200, 10],
        'is_evaluate': True
    }, {
        'id': '3',
        'color': [200, 200, 200],
        'is_evaluate': True
    }]
    with pytest.raises(ValueError):
        b = generator.feature_detection_labelling(a, wrong_config)
    config = [{
        'id': 0,
        'color': [10, 10, 200],
        'is_evaluate': True
    }, {
        'id': 1,
        'color': [200, 10, 10],
        'is_evaluate': True
    }, {
        'id': 2,
        'color': [10, 200, 10],
        'is_evaluate': True
    }, {
        'id': 3,
        'color': [200, 200, 200],
        'is_evaluate': True
    }]
    b = generator.feature_detection_labelling(a, config)
    assert b.shape == (a.shape[0], len(labels))
    assert b.tolist() == [[True, False, False, True],
                          [True, True, True, False]]
Ejemplo n.º 2
0
def test_feature_detection_labelling_concise():
    """Test `feature_detection_labelling` function in `generator` module by considering a concise
    labelling, *i.e.* all labels are represented into the array:
    * as a preliminary verification, check if passing string labels raises an AttributeError
    exception
    * test if output shape is first input shape (batch size) + an additional dimension given by the
    `label_ids` length
    * test if both representation provides the same information (native array on the first hand and
    its one-hot version on the second hand)
    """
    a = np.array([[[0, 0, 0, 2], [3, 3, 0, 2], [3, 3, 3, 0]],
                  [[2, 2, 0, 0], [1, 2, 0, 0], [2, 1, 0, 0]]])
    labels = np.unique(a).tolist()
    MIN, MAX = np.amin(a), np.amax(a)
    with pytest.raises(ValueError):
        b = generator.feature_detection_labelling(a, ['0', '1', '2', '3'])
    b = generator.feature_detection_labelling(a, labels)
    assert b.shape == (a.shape[0], len(labels))
    assert b.tolist() == [[True, False, True, True], [True, True, True, False]]
Ejemplo n.º 3
0
def test_feature_detection_labelling_sparse():
    """Test `feature_detection_labelling` function in `generator` module by considering a sparse
    labelling, *i.e.* the array contains unknown values (to mimic the non-evaluated label
    situations):
    * as a preliminary verification, check if passing string labels raises an AttributeError
    exception
    * test if label length is different from the list of values in the array
    * test if output shape is first input shape (batch size) + an additional dimension given by the
    `label_ids` length
    * test if both representation provides the same information (native array on the first hand and
    its one-hot version on the second hand)
    """
    a = np.array([[[0, 0, 0, 1, 1], [3, 3, 0, 1, 1], [3, 3, 3, 0, 0],
                   [3, 3, 3, 0, 0]],
                  [[1, 1, 2, 1, 2], [3, 2, 2, 1, 3], [1, 1, 1, 2, 1],
                   [1, 1, 2, 3, 2]]])
    labels = np.unique(a).tolist()[:-1]
    with pytest.raises(ValueError):
        b = generator.feature_detection_labelling(a, ['0', '1', '2'])
    b = generator.feature_detection_labelling(a, labels)
    assert len(labels) != np.amax(a) - np.amin(a) + 1
    assert b.tolist() == [[True, True, False], [False, True, True]]
    assert b.shape == (a.shape[0], len(labels))
Ejemplo n.º 4
0
def test_feature_detection_labelling_sparse():
    """Test `feature_detection_labelling` function in `generator` module by
    considering a sparse labelling, *i.e.* the array contains unknown values
    (to mimic the non-evaluated label situations):
    * as a preliminary verification, check if passing string labels raises an
    AttributeError exception
    * test if label length is different from the list of values in the array
    * test if output shape is first input shape (batch size) + an additional
    dimension given by the `label_ids` length
    * test if both representation provides the same information (native array
    on the first hand and its one-hot version on the second hand)
    """
    a = np.array([
        [
            [[10, 10, 200], [10, 10, 200], [10, 10, 200], [200, 10, 10]],
            [
                [200, 200, 200],
                [200, 200, 200],
                [10, 10, 200],
                [200, 10, 10],
            ],
            [
                [200, 200, 200],
                [200, 200, 200],
                [200, 200, 200],
                [10, 10, 200],
            ],
            [
                [200, 200, 200],
                [200, 200, 200],
                [200, 200, 200],
                [10, 10, 200],
            ],
        ],
        [
            [[200, 10, 10], [200, 10, 10], [10, 200, 10], [200, 10, 10]],
            [[200, 200, 200], [10, 200, 10], [10, 200, 10], [10, 200, 10]],
            [[200, 10, 10], [200, 10, 10], [200, 10, 10], [200, 200, 200]],
            [[200, 10, 10], [200, 10, 10], [10, 200, 10], [200, 200, 200]],
        ],
    ])
    labels = np.unique(a.reshape(-1, 3), axis=0).tolist()[:-1]
    wrong_config = [
        {
            "id": "0",
            "color": [10, 10, 200],
            "is_evaluate": True
        },
        {
            "id": "1",
            "color": [200, 10, 10],
            "is_evaluate": True
        },
        {
            "id": "2",
            "color": [10, 200, 10],
            "is_evaluate": True
        },
    ]
    with pytest.raises(ValueError):
        b = generator.feature_detection_labelling(a, wrong_config)
    config = [
        {
            "id": 0,
            "color": [10, 10, 200],
            "is_evaluate": True
        },
        {
            "id": 1,
            "color": [200, 10, 10],
            "is_evaluate": True
        },
        {
            "id": 2,
            "color": [10, 200, 10],
            "is_evaluate": True
        },
    ]
    b = generator.feature_detection_labelling(a, config)
    assert len(labels) != np.amax(a) - np.amin(a) + 1
    assert b.tolist() == [[True, True, False], [False, True, True]]
    assert b.shape == (a.shape[0], len(labels))