Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crashes when creating TF record from joint dataset with some empty engraving categories #13

Open
v-dvorak opened this issue Sep 5, 2024 · 1 comment

Comments

@v-dvorak
Copy link

v-dvorak commented Sep 5, 2024

The error

Traceback (most recent call last):
  File "create_tf_record_from_joint_dataset.py", line 109, in main
    allow_sample_reuse)
  File "create_tf_record_from_joint_dataset.py", line 141, in attempt_to_find_sample_that_is_not_yet_in_dataset
    return random.choice(all_items_in_category)
  File "/opt/python/3.7.15/lib/python3.7/random.py", line 261, in choice
    raise IndexError('Cannot choose from an empty sequence') from None
IndexError: Cannot choose from an empty sequence

When list of documents in given engraving is empty, the random.choice crashes. The code assumes that there will be some documents, even though in documentation it is said, that engraving specifications can be left out.

How to replicate

  1. create dataset with no information about engravings
  2. run create_tf_record_from_joint_dataset.py with the dataset created above

Possible fix

# create_tf_record_from_joint_dataset.py, line 97
with tqdm(desc="Serializing annotations", total=target_size) as progress_bar:
        while samples_written < target_size:                
            current_engraving, number_of_staves = sampling_categories[index % len(sampling_categories)]
            all_items_in_category = dataset[current_engraving][number_of_staves]

            # fix, check if there are any documents
            if len(all_items_in_category) == 0:
                index += 1
                continue
            # end fix

            encoding_succeeded = False
            tf_example = None
@apacha
Copy link
Member

apacha commented Sep 5, 2024

If you've identified the solution, would you mind opening a PR? I'm happy to merge the fix.

v-dvorak added a commit to v-dvorak/MeasureDetector that referenced this issue Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants