This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# L2 Distance | |
def triplet_loss(alpha, emb_dim): | |
def loss(y_true, y_pred): | |
anc, pos, neg = y_pred[:,:emb_size], y_pred[:,emb_size:2*emb_size], y_pred[:,2*emb_size:] | |
distance1 = tf.sqrt(tf.reduce_sum(tf.pow(anc - pos, 2), 1, keepdims=True)) | |
distance2 = tf.sqrt(tf.reduce_sum(tf.pow(anc - neg, 2), 1, keepdims=True)) | |
return tf.reduce_mean(tf.maximum(distance1 - distance2 + alpha, 0.)) | |
return loss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cosine Similarity | |
def triplet_loss(alpha, emb_dim): | |
def loss(y_true, y_pred): | |
anc, pos, neg = y_pred[:,:emb_size], y_pred[:,emb_size:2*emb_size], y_pred[:,2*emb_size:] | |
distance1 = tf.keras.losses.cosine_similarity(anc, pos) | |
distance2 = tf.keras.losses.cosine_similarity(anc, neg) | |
return tf.keras.backend.clip(distance1 - distance2 + alpha, 0., None) | |
return loss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> | |
<item | |
android:drawable="@color/white"/> | |
<item> | |
<bitmap | |
android:gravity="center" | |
android:src="@drawable/ic_icon"/> |