Skip to content

inference_loop crashes on tensor shape mismatch when sequences have variable lengths #296

Description

@ZahraSobhaninia

Description

During evaluation (evaluate_finetune.py), inference_loop crashes with a RuntimeError when sequences in the dataset have different lengths:
RuntimeError: Sizes of tensors must match except in dimension 0. Expected size 512 but got size 440

Suggestion fix:

def pad_patient(patient, max_length):   # for me for instance max_length=512 
    pad_fields = {
        "concepts": 0,
        "segments": 0,
        "ages": 0.0,
        "abspos": 0.0,
    }
    for field, pad_value in pad_fields.items():
        values = getattr(patient, field)
        if len(values) < max_length:
            padded = values + [pad_value] * (max_length - len(values))
        else:
            padded = values[:max_length]
        setattr(patient, field, padded)
    return patient

test_data.patients = [pad_patient(p) for p in test_data.patients]

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐞minor-bugfor non-critical issues🔴bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions