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

Examples of PairCircleLoss #6

Open
jinhong-ni opened this issue Aug 29, 2021 · 2 comments
Open

Examples of PairCircleLoss #6

jinhong-ni opened this issue Aug 29, 2021 · 2 comments

Comments

@jinhong-ni
Copy link

Hi there,

Really appreciate your implementation on Circle loss. I'm trying to utilize circle loss for an eye recognition task, which would use a CNN for encoding eyes and construct positive and negative similarity pairs. I think PairCircleLoss is the most suitable for this task. As the example task provided is still classical classification task, could you please provide some examples of how to use pairwise circle loss? Thank you in advance. :)

@zhen8838
Copy link
Owner

Just like the classical face recognition task, make the batch data input, the y_true is reference image, compute the each data cos similarity with y_true , if current data have the same label with y_true, put it into sp , else put into sn. Finally, use pairwise circle loss.

@jinhong-ni
Copy link
Author

jinhong-ni commented Aug 30, 2021

Thanks for the fast response! I'm a bit new to Tensorflow and keras, so just to wish I'm understanding this correctly.

First we have a model to encode images into vectors:
encoder=tf.keras.Sequential([ ...# model architecture here ])

Then we encode the references, true label images and false label images:
true_label=encoder(X_true) false_label=encoder(X_false) reference=encoder(reference)

And compute cosine similarity scores:
sp=cosine_similarity(true_label,reference) sn=cosine_similarity(false_label,reference)

Then compile the model with PairCircleLoss (This is where I get confused, since similarity score is a unique value, does that mean the shape of the input is ()?):
`model = Model(Input(shape=()), Input(shape=()))

model.compile(
loss=PairCircleLoss(),
optimizer=k.optimizers.Adam(),
metrics=[k.metrics.CategoricalAccuracy('acc')]
)`

And finally we could fit the model with 'sp' and 'sn':
model.fit(sp, sn)

Does the implementation above seem correct? And could you please clarify what should I do to handle the input of the model as similarity scores? Much appreciate for your patience and response!

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

2 participants