-
Notifications
You must be signed in to change notification settings - Fork 635
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
utils.py:FunctionNegativeTripletSelector - 'anchor_positive' referenced before assignment when len(label_indices) < 2 #61
Comments
Can you expand on this, I'm running into the same issue, but you seem to be implying the issue is somehow at the dataset level, but the offending code is called for each batch of data. I don't understand your example, there are way less than 181 labels in TRAINING
labels: [ 4 4 34 34 11 11 3 3 2 2 13 13 32 32 16 16 22 22 39 39 29 29 25 25
8 8 24 24 37 37 41 41 44 44 18 18 21 21 31 31 23 23 1 1 15 15 7 7
26 26 28 28 14 14 19 19] so why does that code show 0/181? I'm really confused as to what the entire set has to do with anything because this seems like a scenario where you can have a bad batch, not a bad training/validation set. Can you expand on how many examples are being sent to It looks like you're only sending in one example in the case of the validation set because you only print one 'label' and you always hit the continue. Obviously you can't do contrastive loss with only one example, so I'm guessing I'm misunderstanding something here. |
After looking at the code for a while, I think what's happening is that if you send in a batch where NONE of your entries has a positive example, then you hit that continue statement for every element in the batch. In which case, there are no triplets since you need at least 1 positive and one negative example to make a triplet. That's why I think the line you pointed out if len(triplets) == 0:
triplets.append([anchor_positive[0], anchor_positive[1], negative_indices[0]]) is just a typo as, Presumably we could just return a constant 1x3 vector in that if statement and the gradient of the loss in that case would be zero and not change the network at all, which is probably the behavior we want. |
@bth5032 my hunch as to what was causing the issue may be incorrect, it was simply based on the fact that the code was failing to create batches just for this dataset. I believe the offending line is a typo, have you had any luck with your proposed solution? |
Hi, yeah I ran a test overnight, just returning a constant vector, in my case if len(triplets) == 0:
triplets.append([0,0,0]) fixed the crash and the model seems to be training just fine |
Great stuff, thank you for taking the time to test that. I ran into this issue but solved it by changing the split of my train-test set. This is a much better solution. |
Hey no problem, thanks for making the post, definitely saved me some time on this! |
Hi,
First off I'd like to say thank you for making this repo, it has been immensely helpful to my research! I believe I have found a bug in utils.py: FunctionNegativeTripletSelector when working with certain datasets. Specifically, the issue occurs on lines 174-175:
When the dataset is small, for example a validation set of an already small dataset, it may not be possible for
label_indices
defined on line 161 to ever be >= 2. This is then checked on line 159-160:If every
label_indices
causes thecontinue
to run, thenlen(triplets)
will be 0. This triggers the offending code on lines 174-175. However at this point under the conditions,anchor_positive
has not yet been defined, leading to a fatal error.To test this, I created a training and validation split, with the validation set being of the following size:
Training occurs as normal, as the offending conditional is never hit:
However the validation set falls foul:
Note the line numbers above may be different from the repo's code due to the print statements. To me, it seems like currently the only way around this error would be to increase the size of the dataset, increasing the chance of
label_indices
at some point being >=2.anchor_positive
needs to be defined somewhere before the offending conditional to stop the error, but I'm unsure where or how in order to fix.The text was updated successfully, but these errors were encountered: