Git Product home page Git Product logo

Comments (6)

bth5032 avatar bth5032 commented on August 16, 2024 2

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

from siamese-triplet.

bth5032 avatar bth5032 commented on August 16, 2024

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 get_triplets inside of OnlineTripletLoss.forward() per batch in your test cases (i.e. in your 'train' and 'validation' set)??

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.

from siamese-triplet.

bth5032 avatar bth5032 commented on August 16, 2024

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 len(triplets) == 0.

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, anchor_positive is only defined in the nested for loop above. Clearly, the author was trying to have a default return case when there are no triplets in the batch, but I too am unsure exactly what he was trying to do there because there is no case where that if statement should work properly.

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.

from siamese-triplet.

Trotts avatar Trotts commented on August 16, 2024

@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?

from siamese-triplet.

Trotts avatar Trotts commented on August 16, 2024

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.

from siamese-triplet.

bth5032 avatar bth5032 commented on August 16, 2024

Hey no problem, thanks for making the post, definitely saved me some time on this!

from siamese-triplet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.