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

RuntimeError: result type Long can't be cast to the desired output type Bool #4

Open
traveling121 opened this issue Jul 30, 2020 · 15 comments

Comments

@traveling121
Copy link

Could you please tell me why it shows "RuntimeError: result type Long can't be cast to the desired output type Bool" when running this code?

@traveling121
Copy link
Author

traveling121 commented Dec 5, 2020 via email

@baopmessi
Copy link

How to solved this problem?

@traveling121
Copy link
Author

traveling121 commented Dec 30, 2020 via email

@zhangxiaopang88
Copy link

Hello, I also encountered this problem, which has not been solved yet. Could you send me a copy of your document, please? thank you.

@zhangxiaopang88
Copy link

How to solved this problem?
Hello, I also encountered this problem, which has not been solved yet. Could you send me a copy of your document, please? thank you.

@traveling121
Copy link
Author

traveling121 commented Jan 11, 2021 via email

@yochaiye
Copy link

Hi @Yolanda2020,

Can you please send me your solution too?

@traveling121
Copy link
Author

traveling121 commented Jan 28, 2021 via email

@5kyler
Copy link

5kyler commented Feb 5, 2021

Hello @Yolanda2020,
could you please send me your solution too??
thanks a lot.

@JAaron9311
Copy link

JAaron9311 commented Feb 14, 2021

Could you please tell me why it shows "RuntimeError: result type Long can't be cast to the desired output type Bool" when running this code?

def _get_triplet_mask(labels):
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")

    # Check that i, j and k are distinct
    indices_equal = torch.eye(labels.size(0), dtype=torch.bool, device=labels.device)
    indices_not_equal = ~indices_equal
    i_not_equal_j = indices_not_equal.unsqueeze(2)
    i_not_equal_k = indices_not_equal.unsqueeze(1)
    j_not_equal_k = indices_not_equal.unsqueeze(0)

    distinct_indices = (i_not_equal_j & i_not_equal_k) & j_not_equal_k

    label_equal = labels.unsqueeze(0) == labels.unsqueeze(1)
    i_equal_j = label_equal.unsqueeze(2)
    i_equal_k = label_equal.unsqueeze(1)

    valid_labels = ~i_equal_k & i_equal_j
    mask = valid_labels & distinct_indices
    return mask.to(device)

you can use the above function to replace to original one.

@5kyler
Copy link

5kyler commented Feb 14, 2021 via email

@Dreamdusty
Copy link

@Yolanda2020 ,hello, could you please send me the file --- 'hard-margin-triplet loss? I meet this problem, too. Thank you

@traveling121
Copy link
Author

traveling121 commented Aug 27, 2021 via email

@zhengyulau
Copy link

Hi, I meet this problem too. Could you please send me your solution?
Thanks a lot!

@traveling121
Copy link
Author

traveling121 commented Sep 30, 2021 via email

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

8 participants