xxlong0 / Wonder3D

Single Image to 3D using Cross-Domain Diffusion for 3D Generation
https://www.xxlong.site/Wonder3D/
GNU Affero General Public License v3.0
4.49k stars 351 forks source link

Selection of Errors in Ranking Loss Computation #163

Open songcbo opened 2 months ago

songcbo commented 2 months ago
def ranking_loss(error, penalize_ratio=0.7, extra_weights=None , type='mean'):
    error, indices = torch.sort(error)
    # only sum relatively small errors
    s_error = torch.index_select(error, 0, index=indices[:int(penalize_ratio * indices.shape[0])])
    if extra_weights is not None:
        weights = torch.index_select(extra_weights, 0, index=indices[:int(penalize_ratio * indices.shape[0])])
        s_error = s_error * weights

    if type == 'mean':
        return torch.mean(s_error)
    elif type == 'sum':
        return torch.sum(s_error)

why selects the errors from the already sorted error tensor ?

why not to select the smallest errors from the original error tensor

dabeschte commented 2 months ago

I just wanted to open a ticket for this myself. I also think that the index_selection is wrong and should be replaced by a simple crop of the error tensor. E.g.: s_error = error[:int(penalize_ratio * error.shape[0])]

Edit: the weights selection is correct though

songcbo commented 2 months ago

I just wanted to open a ticket for this myself. I also think that the index_selection is wrong and should be replaced by a simple crop of the error tensor. E.g.: s_error = error[:int(penalize_ratio * error.shape[0])]

Edit: the weights selection is correct though

When running the owl example with the correct index selection, it seems that the results are not good. The mesh only contains the body and is missing the horns and feet.

dabeschte commented 2 months ago

That's right. I get the same results. In my opinion, this function does not work as intended and can be removed safely. At the moment it is equivalent to a (random) dropout layer.