Ich habe eine Funktion, die einige Tensorflow-Funktionen verwendet. Ich brauche diese Funktion in Theano, da ich auf der Plattform diesen Code verwenden möchte, ist nur Theano installiert und nicht Tensorflow. Ich arbeite hauptsächlich mit Keras, also ist Tensorflow ziemlich kryptisch für mich. Die Funktion sieht wie folgt aus:Ist es möglich, Tensorflow-Code in denano-Code umzuwandeln?
class WeightedBinaryCrossEntropy(object):
def __init__(self, pos_ratio):
neg_ratio = 1. - pos_ratio
self.pos_ratio = tf.constant(pos_ratio, tf.float32)
self.weights = tf.constant(neg_ratio/pos_ratio, tf.float32)
self.__name__ = "weighted_binary_crossentropy({0})".format(pos_ratio)
def __call__(self, y_true, y_pred):
return self.weighted_binary_crossentropy(y_true, y_pred)
def weighted_binary_crossentropy(self, y_true, y_pred):
# Transform to logits
epsilon = tf.convert_to_tensor(K.common._EPSILON, y_pred.dtype.base_dtype)
y_pred = tf.clip_by_value(y_pred, epsilon, 1 - epsilon)
y_pred = tf.log(y_pred/(1 - y_pred))
cost = tf.nn.weighted_cross_entropy_with_logits(y_true, y_pred, self.weights)
return K.mean(cost * self.pos_ratio, axis=-1)
model.compile(loss=WeightedBinaryCrossEntropy(0.05), optimizer=optimizer, metrics=['accuracy'])
Installation Tensorflow auf der Plattform ist nicht möglich. Ich habe den Code von hier https://github.com/fchollet/keras/issues/2115
Also gibt es Funktionen in Theano, die wie die Funktionen in Tensorflow funktionieren?
Vielen Dank, wird es einige Zeit dauern, um es zu testen: Nach dem Test werde ich es wohl akzeptieren . –