Skip to content
Snippets Groups Projects
Commit 4d41a41d authored by Falguni Ghosh's avatar Falguni Ghosh
Browse files

Upload New File

parent 82e00c7f
Branches android-msm-sturgeon-3.10-marshmallow-mr1-wear-release
Tags android-wear-6.0.1_r0.60
No related merge requests found
import numpy as np
class CrossEntropyLoss:
def __init__(self):
self.prediction_tensor = None
def forward(self, prediction_tensor, label_tensor):
loss = 0
a = prediction_tensor * label_tensor
for i in range(a.shape[0]):
loss = loss + (-np.log(np.sum(a[i]) + np.finfo(float).eps))
self.prediction_tensor = np.copy(prediction_tensor)
return loss
def backward(self, label_tensor):
error_tensor = np.empty(label_tensor.shape)
for i in range(label_tensor.shape[0]):
error_tensor[i] = - label_tensor[i]/(self.prediction_tensor[i] + np.finfo(float).eps)
return error_tensor
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment