Problem uploading video segmentation annotations

Hi,

I’m trying to upload pre-labels annotations for some videos.
I’ve to annotate multiple segments in the video, and I’m uploading them with:

  segment_index = 0
  page_annotations = []
  for page, (start, end) in page_to_frames.items():
      radio_annotation = [
          lb_types.VideoClassificationAnnotation(
              name="pages",
              frame=start+1,
              segment_index=segment_index,
              value=lb_types.Radio(answer = 
                                       lb_types.ClassificationAnswer(name=str(page+1)))
          ),
          lb_types.VideoClassificationAnnotation(
              name="pages",
              frame=int(min(end+1,pages.shape[0])),
              segment_index=segment_index,
              value=lb_types.Radio(answer = 
                                       lb_types.ClassificationAnswer(name=str(page+1)))
          )
      ]
      page_annotations+=radio_annotation
      segment_index+=1

and then:

  label = []
  for annotation in page_annotations:
      label.append(
          lb_types.Label(
              data= {"global_key": global_key},
              annotations = annotation
          )
      )
  
  upload_job = MALPredictionImport.create_from_objects(
  client = client,
  project_id = "project_id",
  name = "mal_job"+str(uuid.uuid4()),
  predictions = label)

In the annotation tool, the problem is that the video is segmented correctly, but just one label remains fixed for the whole video and does not change as in the radio_annotations uploaded.

Posting here the ontology too

I’ve also tried to create a unique annotation per segment, but what I see while annotating is

That shows only the first annotation (green line) in the choice bar

Hi,
Unfortunately, we have an issue with our built-in Label objects. We are hoping to get this resolved soon. But to workaround this, you can import your annotations directly as Python dictionaries. Here is some sample code that you could use:

"""
Each feature gets a NDJSON were answer is a list with answer and frame is individual
{
    "name" : "<Feature Name>"
    "answer" : [{"name": <Answer Name>, "frames": [<List of single frames with answer>]}]
    "dataRow": {
        "globalKey": data_row.global_key
    }
}
"""
import random
annotations_ndjson = []

annotate_1 = {
    "name":"test",
    "answer": [],
        "dataRow": {
        "globalKey": global_key
    }
    }

annotate_2 = {
    "name":"test_2",
    "answer": [],
    "dataRow": {
        "globalKey": global_key
    }
    }
for frame in range(frames):
    answer = random.choice([1,2,3])
    answer_2 = random.choice([1,2,3])
    index = next((index for (index, d) in enumerate(annotate_1["answer"]) if d["name"] == str(answer)), None)
    if index == None:
      annotate_1["answer"].append({"name": str(answer), "frames": [{"start": str(frame+1), "end": str(frame+1)}]})
    else:
      previous_number = next((previous_number for (previous_number, d) in enumerate(annotate_1["answer"][index]["frames"]) if d["end"] == str(frame)), None)
      if previous_number == None:
        annotate_1["answer"][index]["frames"].append({"start": str(frame+1), "end": str(frame+1)})
      else:
        annotate_1["answer"][index]["frames"][previous_number]["end"] = str(frame+1)
    index = next((index for (index, d) in enumerate(annotate_2["answer"]) if d["name"] == str(answer_2)), None)
    if index == None:
      annotate_2["answer"].append({"name": str(answer_2), "frames": [{"start": str(frame+1), "end": str(frame+1)}]})
    else:
      previous_number = next((previous_number for (previous_number, d) in enumerate(annotate_2["answer"][index]["frames"]) if d["end"] == str(frame)), None)
      if previous_number == None:
        annotate_2["answer"][index]["frames"].append({"start": str(frame+1), "end": str(frame+1)})
      else:
        annotate_2["answer"][index]["frames"][previous_number]["end"] = str(frame+1)

annotations_ndjson.append(annotate_1)
annotations_ndjson.append(annotate_2)

pprint(annotations_ndjson[1])

Thanks,
Gabe

2 Likes

Thank you, this solved my problem!