def test_instance_confidence_map_generator(min_labels): labels_reader = providers.LabelsReader(min_labels) instance_centroid_finder = instance_centroids.InstanceCentroidFinder( center_on_anchor_part=True, anchor_part_names="A", skeletons=labels_reader.labels.skeletons, ) instance_cropper = instance_cropping.InstanceCropper( crop_width=160, crop_height=160 ) instance_confmap_generator = InstanceConfidenceMapGenerator( sigma=5, output_stride=2, all_instances=False ) ds = labels_reader.make_dataset() ds = instance_centroid_finder.transform_dataset(ds) ds = instance_cropper.transform_dataset(ds) ds = instance_confmap_generator.transform_dataset(ds) example = next(iter(ds)) assert example["instance_confidence_maps"].shape == (80, 80, 2) assert example["instance_confidence_maps"].dtype == tf.float32 assert "all_instance_confidence_maps" not in example points = ( example["center_instance"].numpy() / instance_confmap_generator.output_stride ) cms = example["instance_confidence_maps"].numpy() np.testing.assert_allclose( cms[(points[:, 1]).astype(int), (points[:, 0]).astype(int), :], [[0.9139312, 0.0], [0.0, 0.94459903]], )
def test_instance_cropper_keeping_full_image(min_labels): labels_reader = providers.LabelsReader(min_labels) instance_centroid_finder = instance_centroids.InstanceCentroidFinder( center_on_anchor_part=True, anchor_part_names="A", skeletons=labels_reader.labels.skeletons) instance_cropper = instance_cropping.InstanceCropper(crop_width=160, crop_height=160, keep_full_image=True) ds = instance_centroid_finder.transform_dataset( labels_reader.make_dataset()) ds = instance_cropper.transform_dataset(ds) example = next(iter(ds)) assert example["instance_image"].shape == (160, 160, 1) assert example["instance_image"].dtype == tf.uint8 assert example["full_image_height"] == 384 assert example["full_image_height"].dtype == tf.int32 assert example["full_image_width"] == 384 assert example["full_image_width"].dtype == tf.int32 assert example["image"].shape == (384, 384, 1) assert example["image"].dtype == tf.uint8
def test_instance_confidence_map_generator_with_all_instances(min_labels): labels_reader = providers.LabelsReader(min_labels) instance_centroid_finder = instance_centroids.InstanceCentroidFinder( center_on_anchor_part=True, anchor_part_names="A", skeletons=labels_reader.labels.skeletons, ) instance_cropper = instance_cropping.InstanceCropper(crop_width=160, crop_height=160) instance_confmap_generator = InstanceConfidenceMapGenerator( sigma=5 / 2, output_stride=2, all_instances=True) ds = labels_reader.make_dataset() ds = instance_centroid_finder.transform_dataset(ds) ds = instance_cropper.transform_dataset(ds) ds = instance_confmap_generator.transform_dataset(ds) example = next(iter(ds)) assert "instance_confidence_maps" in example assert example["all_instance_confidence_maps"].shape == (80, 80, 2) assert example["all_instance_confidence_maps"].dtype == tf.float32 instances = (example["all_instances"].numpy() / instance_confmap_generator.output_stride) all_cms = example["all_instance_confidence_maps"].numpy() x = (instances[:, :, 0]).astype(int) y = (instances[:, :, 1]).astype(int) x[(x < 0) | (x >= all_cms.shape[1])] = 0 y[(y < 0) | (y >= all_cms.shape[0])] = 0 np.testing.assert_allclose( all_cms[y, x, :], [[[0.91393119, 0.], [0., 0.94459903]], [[0., 0.], [0., 0.]]], atol=1e-6)
def test_instance_cropper(min_labels): labels_reader = providers.LabelsReader(min_labels) instance_centroid_finder = instance_centroids.InstanceCentroidFinder( center_on_anchor_part=True, anchor_part_names="A", skeletons=labels_reader.labels.skeletons) instance_cropper = instance_cropping.InstanceCropper(crop_width=160, crop_height=160, keep_full_image=False) ds = instance_centroid_finder.transform_dataset( labels_reader.make_dataset()) ds = instance_cropper.transform_dataset(ds) example = next(iter(ds)) assert example["instance_image"].shape == (160, 160, 1) assert example["instance_image"].dtype == tf.uint8 assert example["bbox"].shape == (4, ) assert example["bbox"].dtype == tf.float32 assert example["center_instance"].shape == (2, 2) assert example["center_instance"].dtype == tf.float32 assert example["center_instance_ind"] == 0 assert example["center_instance_ind"].dtype == tf.int32 assert example["all_instances"].shape == (2, 2, 2) assert example["all_instances"].dtype == tf.float32 assert example["centroid"].shape == (2, ) assert example["centroid"].dtype == tf.float32 assert example["full_image_height"] == 384 assert example["full_image_height"].dtype == tf.int32 assert example["full_image_width"] == 384 assert example["full_image_width"].dtype == tf.int32 assert example["video_ind"] == 0 assert example["video_ind"].dtype == tf.int32 assert example["frame_ind"] == 0 assert example["frame_ind"].dtype == tf.int64 np.testing.assert_array_equal(example["scale"], (1.0, 1.0)) assert example["scale"].dtype == tf.float32 assert example["skeleton_inds"].shape == (2, ) assert example["skeleton_inds"].dtype == tf.int32 assert "image" not in example