python - Tensorflow compute_weighted_loss Example -
i want use tensorflows tf.losses.compute_weighted_loss cannot find example. have multi-class classification problem , use tf.nn.sigmoid_cross_entropy_with_logits loss. want weigh errors each label independently. let's have n labels, means need n-sized weight vector. unfortunately tf expects me pass (b, n) shaped matrix of error weights, b batch size. need repeat weight vector b times. that's okay given fixed batch size, if batch size variable (e.g. smaller batch @ end of dataset) have adapt. there way around or did miss something?
i had reshape vector (n,) (1,n) make broadcasting possible:
error_weights = error_weights.reshape(1, error_weights.shape[0])
Comments
Post a Comment