def test_table_specials(): table = wandb.Table( columns=["image", "table"], optional=False, dtype=[data_types.Image, data_types.Table], ) with pytest.raises(TypeError): table.add_data(None, None) # Infers specific types from first valid row table.add_data( data_types.Image( np.random.rand(10, 10), boxes=box_annotation, masks=mask_annotation, ), data_types.Table(data=[[1, True, None]]), ) # Denies conflict with pytest.raises(TypeError): table.add_data( "hello", data_types.Table(data=[[1, True, None]]), ) # Denies conflict with pytest.raises(TypeError): table.add_data( data_types.Image( np.random.rand(10, 10), boxes=box_annotation, masks=mask_annotation, ), data_types.Table(data=[[1, "True", None]]), ) # allows further refinement table.add_data( data_types.Image( np.random.rand(10, 10), boxes=box_annotation, masks=mask_annotation, ), data_types.Table(data=[[1, True, 1]]), ) # allows addition table.add_data( data_types.Image( np.random.rand(10, 10), boxes=box_annotation, masks=mask_annotation, ), data_types.Table(data=[[1, True, 1]]), )
def test_image_accepts_bounding_boxes_optional_args(mocked_run): img = data_types.Image(image, boxes={"predictions": {"box_data": boxes_with_removed_optional_args}}) img.bind_to_run(mocked_run, "images", 0) img_json = img.to_json(mocked_run) path = img_json["boxes"]["predictions"]["path"] assert os.path.exists(os.path.join(mocked_run.dir, path))
def test_single_image(history): image = np.random.randint(255, size=(28, 28)) history.add({"images": data_types.Image(image)}) h = disk_history() assert h[0]["images"] == {'_type': 'images', 'count': 1, 'height': 28, 'width': 28} assert os.path.exists("media/images/images_0.jpg")
def test_image_accepts_bounding_boxes_optional_args(): with CliRunner().isolated_filesystem(): run = wandb.wandb_run.Run() img = data_types.Image(image, boxes=boxes_with_removed_optional_args) img.bind_to_run(run, "images", 0) img_json = img.to_json(run) path = img_json["boxes"]["path"] assert os.path.exists(os.path.join(run.dir, path))
def test_list_of_images(history): image = np.random.randint(255, size=(28, 28)) history.add({"images": [data_types.Image(image)]}) h = disk_history(history) expected = { '_type': 'images', 'count': 1, 'height': 28, 'width': 28, }
def test_single_image(history): image = np.random.randint(255, size=(28, 28)) history.add({"images": data_types.Image(image)}) h = disk_history(history) assert os.path.exists( os.path.join(history._run.dir, h[0]['images']['path'])) assert set(h[0]["images"].items()) >= set({ '_type': 'image-file', 'height': 28, 'width': 28, }.items())
def test_image_type(): wb_type = data_types._ImageFileType() image_simple = data_types.Image(np.random.rand(10, 10)) wb_type_simple = data_types._ImageFileType.from_obj(image_simple) image_annotated = data_types.Image( np.random.rand(10, 10), boxes={ "box_predictions": { "box_data": [ { "position": { "minX": 0.1, "maxX": 0.2, "minY": 0.3, "maxY": 0.4, }, "class_id": 1, "box_caption": "minMax(pixel)", "scores": { "acc": 0.1, "loss": 1.2 }, }, ], "class_labels": class_labels, }, "box_ground_truth": { "box_data": [ { "position": { "minX": 0.1, "maxX": 0.2, "minY": 0.3, "maxY": 0.4, }, "class_id": 1, "box_caption": "minMax(pixel)", "scores": { "acc": 0.1, "loss": 1.2 }, }, ], "class_labels": class_labels, }, }, masks={ "mask_predictions": { "mask_data": np.random.randint(0, 4, size=(30, 30)), "class_labels": class_labels, }, "mask_ground_truth": { "path": im_path, "class_labels": class_labels }, }, ) wb_type_annotated = data_types._ImageFileType.from_obj(image_annotated) image_annotated_differently = data_types.Image( np.random.rand(10, 10), boxes={ "box_predictions": { "box_data": [ { "position": { "minX": 0.1, "maxX": 0.2, "minY": 0.3, "maxY": 0.4, }, "class_id": 1, "box_caption": "minMax(pixel)", "scores": { "acc": 0.1, "loss": 1.2 }, }, ], "class_labels": class_labels, }, }, masks={ "mask_predictions": { "mask_data": np.random.randint(0, 4, size=(30, 30)), "class_labels": class_labels, }, "mask_ground_truth_2": { "path": im_path, "class_labels": class_labels }, }, ) assert wb_type.assign(image_simple) == wb_type_simple assert wb_type.assign(image_annotated) == wb_type_annotated # OK to assign Images with disjoint class set assert wb_type_annotated.assign(image_simple) == wb_type_annotated # Merge when disjoint assert wb_type_annotated.assign( image_annotated_differently) == data_types._ImageFileType( box_layers={ "box_predictions": {1, 2, 3}, "box_ground_truth": {1, 2, 3} }, box_score_keys={"loss", "acc"}, mask_layers={ "mask_ground_truth_2": set(), "mask_ground_truth": set(), "mask_predictions": {1, 2, 3}, }, class_map={ "1": "tree", "2": "car", "3": "road" }, )
def test_image_type(): wb_type = data_types._ImageFileType() image_simple = data_types.Image(np.random.rand(10, 10)) wb_type_simple = data_types._ImageFileType.from_obj(image_simple) image_annotated = data_types.Image( np.random.rand(10, 10), boxes={ "box_predictions": { "box_data": [ { "position": { "minX": 0.1, "maxX": 0.2, "minY": 0.3, "maxY": 0.4, }, "class_id": 1, "box_caption": "minMax(pixel)", "scores": { "acc": 0.1, "loss": 1.2 }, }, ], "class_labels": class_labels, }, "box_ground_truth": { "box_data": [ { "position": { "minX": 0.1, "maxX": 0.2, "minY": 0.3, "maxY": 0.4, }, "class_id": 1, "box_caption": "minMax(pixel)", "scores": { "acc": 0.1, "loss": 1.2 }, }, ], "class_labels": class_labels, }, }, masks={ "mask_predictions": { "mask_data": np.random.randint(0, 4, size=(30, 30)), "class_labels": class_labels, }, "mask_ground_truth": { "path": im_path, "class_labels": class_labels }, }, ) wb_type_annotated = data_types._ImageFileType.from_obj(image_annotated) image_annotated_differently = data_types.Image( np.random.rand(10, 10), boxes={ "box_predictions": { "box_data": [ { "position": { "minX": 0.1, "maxX": 0.2, "minY": 0.3, "maxY": 0.4, }, "class_id": 1, "box_caption": "minMax(pixel)", "scores": { "acc": 0.1, "loss": 1.2 }, }, ], "class_labels": class_labels, }, }, masks={ "mask_predictions": { "mask_data": np.random.randint(0, 4, size=(30, 30)), "class_labels": class_labels, }, "mask_ground_truth_2": { "path": im_path, "class_labels": class_labels }, }, ) assert wb_type.assign(image_simple) == wb_type_simple assert wb_type.assign(image_annotated) == wb_type_annotated assert wb_type_annotated.assign(image_simple) == InvalidType() assert wb_type_annotated.assign( image_annotated_differently) == InvalidType()