0

I have implemented the vast majority of a multi-input model, and I am struggling in the last few steps of defining a single loss function for 2 incoming logit tensors.

Lets say I have the following:

logits_cnn =  tf.layers.dense(input1) # shape is [batch_size, num_classes] (e.g. [64,1])
logits_lstm = tf.layers.dense(input2) # shape is [batch_size, num_classes] (e.g. [64,1])

Then I want to feed them to the following loss function:

tf.losses.sigmoid_cross_entropy(multi_class_labels, logits, ...)

I was thinking of something like this:

logits_concat = tf.concat(values = [logits_cnn, logits_lstm], axis= -1, name='concat_logits')
loss = tf.losses.sigmoid_cross_entropy(multi_class_labels= y, logits = logits_concat)

Does the loss implementation make sense? I feel that this is not a conceptually correct approach. As an example, if y is shape [64,1] and logits_concat is shape [64,2] , then I'm suggesting that there's 2 classes in play and that's not my intent.

js_55
  • 177
  • 1
  • 1
  • 9
  • tf.concat(values = [logits_cnn, logits_lstm], axis= -1) ,will have shape = (64,2) not(128,1) – Tou You Aug 24 '20 at 00:25
  • @TouYou , great catch. I did a quick check, and you're absolutely right on the dimensions. I will update my question's commentary. my question still stands in general with correct documentation. – js_55 Aug 24 '20 at 02:31
  • to get one logit just add another layer (sigmoid ,softmax.. )before loss ops , and use the two logits you have as input (=features) – Tou You Aug 24 '20 at 10:05

0 Answers0