You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running the notebook: Parametric t-SNE (Keras).ipynb, I followed the notebook by constructing the neural network using the customized loss function. However, I received ValueError from Keras when trying to train the neural network.
Customized loss function:
# P is the joint probabilities for this batch (Keras loss functions call this y_true)
# activations is the low-dimensional output (Keras loss functions call this y_pred)
def tsne(P, activations):
d = 2 # TODO: should set this automatically, but the above is very slow for some reason
n = batch_size # TODO: should set this automatically
v = d - 1.
eps = K.variable(10e-15) # needs to be at least 10e-8 to get anything after Q /= K.sum(Q)
sum_act = K.sum(K.square(activations), axis=1)
Q = K.reshape(sum_act, [-1, 1]) + -2 * K.dot(activations, K.transpose(activations))
Q = (sum_act + Q) / v
Q = K.pow(1 + Q, -(v + 1) / 2)
Q *= K.variable(1 - np.eye(n))
Q /= K.sum(Q)
Q = K.maximum(Q, eps)
C = K.log((P + eps) / (Q + eps))
C = K.sum(P * C)
return C
ValueError: Error when checking target: expected dense_4 to have shape (None, 2) but got array with shape (60000, 5000)
Since the loss function has been customized to received different shape of y_true (batch_size x batch_size) and y_pred (batch_size x 2), I was not sure why I received the error above. Note that the batch_size here is 5000, which is the same value as the notebook is using.
The text was updated successfully, but these errors were encountered:
When running the notebook:
Parametric t-SNE (Keras).ipynb
, I followed the notebook by constructing the neural network using the customized loss function. However, I received ValueError from Keras when trying to train the neural network.ValueError: Error when checking target: expected dense_4 to have shape (None, 2) but got array with shape (60000, 5000)
Since the loss function has been customized to received different shape of y_true (batch_size x batch_size) and y_pred (batch_size x 2), I was not sure why I received the error above. Note that the batch_size here is 5000, which is the same value as the notebook is using.
The text was updated successfully, but these errors were encountered: