def test_image_shape_to_grids(self): (y_grid, x_grid) = ta_utils.image_shape_to_grids(height=2, width=3) expected_y_grid = np.array([[0, 0, 0], [1, 1, 1]]) expected_x_grid = np.array([[0, 1, 2], [0, 1, 2]]) np.testing.assert_array_equal(y_grid.numpy(), expected_y_grid) np.testing.assert_array_equal(x_grid.numpy(), expected_x_grid)
def graph_fn(): (y_grid, x_grid) = ta_utils.image_shape_to_grids(height=3, width=5) y_coordinates = tf.constant([1.5, 0.5], dtype=tf.float32) x_coordinates = tf.constant([2.5, 4.5], dtype=tf.float32) sigma = tf.constant([0.1, 0.5], dtype=tf.float32) channel_onehot = tf.constant([[1, 0, 0], [0, 1, 0]], dtype=tf.float32) channel_weights = tf.constant([1, 1], dtype=tf.float32) heatmap = ta_utils.coordinates_to_heatmap(y_grid, x_grid, y_coordinates, x_coordinates, sigma, channel_onehot, channel_weights) return heatmap
def test_coordinates_to_heatmap(self): (y_grid, x_grid) = ta_utils.image_shape_to_grids(height=3, width=5) y_coordinates = tf.constant([1.5, 0.5], dtype=tf.float32) x_coordinates = tf.constant([2.5, 4.5], dtype=tf.float32) sigma = tf.constant([0.1, 0.5], dtype=tf.float32) channel_onehot = tf.constant([[1, 0, 0], [0, 1, 0]], dtype=tf.float32) channel_weights = tf.constant([1, 1], dtype=tf.float32) heatmap = ta_utils.coordinates_to_heatmap(y_grid, x_grid, y_coordinates, x_coordinates, sigma, channel_onehot, channel_weights) # Peak at (1, 2) for the first class. self.assertAlmostEqual(1.0, heatmap.numpy()[1, 2, 0]) # Peak at (0, 4) for the second class. self.assertAlmostEqual(1.0, heatmap.numpy()[0, 4, 1])
def graph_fn(): (y_grid, x_grid) = ta_utils.image_shape_to_grids(height=2, width=3) return y_grid, x_grid