sanku-lib/image_triplet_loss

Different flavor of layers

aseembh2001 opened this issue · 2 comments

Hi,

Thanks for the wonderful algorithm. Helped me a lot.
I am trying to implement a different flavor of networks for my algortihm:

def conv_net(self, inp, reuse=False):
        vgg_model = VGG16(weights=None, include_top=False,input_shape=(32,32,3),input_tensor=inp)
        #print(" vgg_model_input {}".format(vgg_model.input))
        x = vgg_model.output
        x = GlobalAveragePooling2D()(x)
        x = Dense(4096, activation='relu')(x)
        x = Dropout(0.6)(x)
        x = Dense(4096, activation='relu')(x)
        x = Dropout(0.6)(x)
        x = Lambda(lambda  x_: K.l2_normalize(x,axis=1))(x)
        convnet_model = Model(inputs=vgg_model.input,outputs=x)
        
 
        first_conv = Conv2D(96, kernel_size=(8, 8),strides=(16,16), padding='same',name="conv_layer_1")(inp)
        first_max = MaxPool2D(pool_size=(3,3),strides = (4,4),padding='same')(first_conv)
        first_max = Flatten()(first_max)
        first_max = Lambda(lambda  x: K.l2_normalize(x,axis=1))(first_max)


        second_conv = Conv2D(96, kernel_size=(8, 8),strides=(32,32), padding='same',name="conv_layer_2")(inp)
        second_max = MaxPool2D(pool_size=(7,7),strides = (2,2),padding='same')(second_conv)
        second_max = Flatten()(second_max)
        second_max = Lambda(lambda  x: K.l2_normalize(x,axis=1))(second_max)

        merge_one = concatenate([first_max, second_max])

        merge_two = concatenate([merge_one, convnet_model.output])
        emb = Dense(512)(merge_two)
        l2_norm_final = Lambda(lambda  x: K.l2_normalize(x,axis=1))(emb)
        #emb = Flatten()(emb)
        print("Embedding {}".format(emb))
        
        return l2_norm_final

However when I train using these layers, my model only produces nonzero loss for first iteration, all further losses are 0.0.

Could you think of a reason why that might be happening ?

I am new to tensorflow to the struggles.

Thanks

I think I got it, in my loss function distance1-distance2 +margin is negative, that's why max of '0' is taken as loss

It happens when your model is not able to learn proper embeddings to maintain a at least "margin" difference between similar and dissimilar data point. Try to adjust the margin and see if it works otherwise look for other model architecture.
Please let us know if this issue is still continuing.