mpc001 / auto_avsr

Auto-AVSR: Lip-Reading Sentences Project
Apache License 2.0
158 stars 40 forks source link

`cut_or_pad` function is wrong #20

Closed xiabingquan closed 8 months ago

xiabingquan commented 9 months ago

The current version is:

def cut_or_pad(data, size, dim=0):
    if data.size(dim) < size:
        padding = size - data.size(dim)
        data = torch.nn.functional.pad(data, (0, padding), "constant")
    elif data.size(dim) > size:
        data = data[:size]
    assert data.size(dim) == size
    return data

The right version should be:

def cut_or_pad(data, size, dim=0):
    if data.size(dim) < size:
        padding = size - data.size(dim)
        data = torch.nn.functional.pad(data, (0, 0, 0, padding), "constant")           # modified
        size = data.size(dim)                                                          # added
    elif data.size(dim) > size:
        data = data[:size]
    assert data.size(dim) == size
    return data
mpc001 commented 8 months ago

Hi @xiabingquan, the bug has been fixed. Thank you!

jeonhuhuhu commented 8 months ago
def cut_or_pad(data, size, dim=0):
    if data.size(dim) < size:
        padding = size - data.size(dim)
        data = torch.nn.functional.pad(data, (0, 0, 0, padding), "constant")           # modified
        size = data.size(dim)                                                          # added
    elif data.size(dim) > size:
        data = data[:size]
    assert data.size(dim) == size
    return data

Does this problem affect the accuracy?

xiabingquan commented 8 months ago
def cut_or_pad(data, size, dim=0):
    if data.size(dim) < size:
        padding = size - data.size(dim)
        data = torch.nn.functional.pad(data, (0, 0, 0, padding), "constant")           # modified
        size = data.size(dim)                                                          # added
    elif data.size(dim) > size:
        data = data[:size]
    assert data.size(dim) == size
    return data

Does this problem affect the accuracy?

In my case, it raises errors if not modified.

jeonhuhuhu commented 8 months ago
def cut_or_pad(data, size, dim=0):
    if data.size(dim) < size:
        padding = size - data.size(dim)
        data = torch.nn.functional.pad(data, (0, 0, 0, padding), "constant")           # modified
        size = data.size(dim)                                                          # added
    elif data.size(dim) > size:
        data = data[:size]
    assert data.size(dim) == size
    return data

Does this problem affect the accuracy?

In my case, it raises errors if not modified.

What kind of error is the error you mentioned? Is it an error that the code itself does not execute?