Annotation for binary image segmentation in Prodigy?

Ah! That's a good question.

Introduction

Before showing the solution, it helps to show you you would need to prepare the data upfront. So I'll label one example from a dataset I have locally.

python -m prodigy image.manual cat-demo images/ --label noa,sok --remove-base64

The dataset has pictures of my cats, and here you see an annotated example of both.

I hit "accept," and after that, I make sure that I also hit the save button.

I can now see this annotated example in json.

python -m prodigy db-out cat-demo > example_annot.jsonl 

The single example in this file looks like this:

{
    "image":"images/img1.png",
    "text":"img1",
    "meta":{"file":"img1.png"},
    "path":"images/img1.png",
    "_input_hash":321949276,
    "_task_hash":1956213220,
    "_is_binary":false,
    "_view_id":"image_manual",
    "width":485,
    "height":313,
    "spans":[
        {"id":"e0701f3f-68b3-45b3-b344-28d25f3c8d47","label":"noa","color":"yellow","x":6.5,"y":9,"height":284,"width":224,"center":[118.5,151],"type":"rect","points":[[6.5,9],[6.5,293],[230.5,293],[230.5,9]]},
        {"id":"08a5772a-4094-42fc-b069-16693df98490","label":"sok","color":"cyan","x":166.5,"y":36,"height":235,"width":310,"center":[321.5,153.5],"type":"rect","points":[[166.5,36],[166.5,271],[476.5,271],[476.5,36]]}],
    "answer":"accept","_timestamp":1658907411
}

Notice how the spans contain the coordinates? This is how Prodigy stores the annotation, but it's also what we need to supply Prodigy if we want it to draw the coordinates.

Passing these along

You can pass this file with annotations to Prodigy, you just have to make it aware that you're no longer giving it a folder of images. Notice in the command below that I'm passing --loader jsonl.

python -m prodigy image.manual cat-demo example_annot.jsonl --label noa,sok --remove-base64 --loader jsonl

And it gives an interface that has the annotations pre-filled.

Adding annotations yourself

You can use your own ML model to pre-fill the example_annot.jsonl file for Prodigy with spans that select the item you're interested in. Prodigy gives you full control in how you pre-fill these spans, but you will need to supply your own ML model.