Ejemplo n.º 1
0
def test_update_mse_should_have_the_same_effect_as_full_mse():
    bounds = np.array([[50, 60, 50], [50, 60, 51], [50, 60, 52]])
    target = np.random.random((100, 100, 3))
    img = np.random.random((100, 100, 3))
    mse = mse_full(target, img)
    img[50, 50:61] = 0.5
    img[51, 50:61] = 0.4
    img[52, 50:61] = 0.3
    update_mse(mse, bounds, img, target)
    assert np.array_equal(mse, mse_full(target, img))
Ejemplo n.º 2
0
def test_broken_partial_mse(x1, y1, x2, y2, x3, y3, x4, y4):
    img = np.zeros((500, 500, 3))
    target = np.zeros((500, 500, 3))
    distance = np.zeros((500, 500, 3))
    assert img.dtype == np.float
    assert target.dtype == np.float
    assert distance.dtype == np.float
    r = Quadrangle(points=np.array([[x1, y1], [x2, y2], [x3, y3], [x4, y4]],
                                   dtype=np.int64),
                   alpha=0.5)
    bounds = r.render(img, target)
    update_mse(distance=distance, bounds=bounds, img=img, target=target)
    assert np.array_equal(distance, mse_full(target, img))
    assert np.mean(distance) == np.mean(mse_full(target, img))
Ejemplo n.º 3
0
def test_update_mse_should_calculate_the_same_values_as_full_mse_for_bounded_area(
):
    mse = np.zeros((100, 100, 3))
    bounds = np.array([[50, 60, 50], [50, 60, 51], [50, 60, 52]])
    img = np.random.random((100, 100, 3))
    target = np.random.random((100, 100, 3))
    update_mse(mse, bounds, img, target)
    full = mse_full(target, img)
    assert np.array_equal(full[np.where(mse > 0)], mse[np.where(mse > 0)])
Ejemplo n.º 4
0
 def get(self, X):
     if self.model is None:
         self.model = self.model_cls(**self.model_params)
     if self.target_activations is None:
         self.target_activations = self.model.get_activations(
             self.canvas.target)
     img_activations = self.model.get_activations(X)
     target_activations = np.repeat(self.target_activations,
                                    X.shape[0],
                                    axis=0)
     # todo: np.mean with axis=(1,2,3)
     reward = self._mean(mse_full(target_activations, img_activations))
     assert reward.shape[0] == X.shape[0], f'reward.shape = {reward.shape}'
     return reward
Ejemplo n.º 5
0
def test_mse_full_should_return_float_array():
    target = np.random.random((100, 100))
    x = np.random.random((100, 100))
    mse = mse_full(target=target, x=x)
    assert mse.dtype == np.float
Ejemplo n.º 6
0
def test_mse_full_should_calculate_l2_properly():
    target = np.array([[2, 4], [4, 3]])
    x = np.array([[2, 5], [0, 2]])
    mse = mse_full(target=target, x=x)
    assert np.array_equal(mse, np.array([[0, 1], [16, 1]]))
Ejemplo n.º 7
0
def test_mse_full_should_be_max_when_target_is_white_and_x_is_black():
    target = np.full((100, 100), 255)
    x = np.zeros((100, 100))
    mse = mse_full(target=target, x=x)
    assert np.array_equal(mse, np.full(target.shape, 255 * 255))
Ejemplo n.º 8
0
def test_mse_full_should_be_all_zeros_when_target_and_x_are_identical():
    target = np.random.random((100, 100))
    x = target.copy()
    mse = mse_full(target=target, x=x)
    assert np.array_equal(mse, np.zeros(target.shape))