Exemple #1
0
def subtract(x, biases):
    if isinstance(x, expr.Constant) and isinstance(biases, expr.Constant):
        return expr.Constant(subtract_fn.forward([x.value, biases.value])[0])
    else:
        return expr.Apply(subtract_fn, [x, biases])
Exemple #2
0
def softmax(x):
    if isinstance(x, expr.Constant):
        return expr.Constant(softmax_fn.forward([x.value])[0])
    else:
        return expr.Apply(softmax_fn, [x])
Exemple #3
0
def reshape(values, new_shape):
    if isinstance(values, expr.Constant):
        return expr.Constant(Reshape(new_shape).forward([values.value]))
    else:
        return expr.Apply(Reshape(new_shape), [values])
Exemple #4
0
def mean(values, dims):
    if isinstance(values, expr.Constant):
        return expr.Constant(Mean(dims).forward(values.value))
    else:
        return expr.Apply(Mean(dims), [values])
def squared_difference(x, weights):
    if isinstance(x, expr.Constant) and isinstance(weights, expr.Constant):
        return expr.Constant(squared_difference_fn.forward([x.value, weights.value])[0])
    else:
        return expr.Apply(squared_difference_fn, [x, weights])
Exemple #6
0
def sigmoid_cross_entropy(x, labels):
    if isinstance(x, expr.Constant) and isinstance(labels, expr.Constant):
        return expr.Constant(
            sigmoid_cross_entropy_fn.forward([x.value, labels.value])[0])
    else:
        return expr.Apply(sigmoid_cross_entropy_fn, [x, labels])
Exemple #7
0
def upsample(values, scale):
    if isinstance(values, expr.Constant):
        return expr.Constant(Upsample(scale).forward(values.value))
    else:
        return expr.Apply(Upsample(scale), [values])
Exemple #8
0
def add_biases(x, biases):
    if isinstance(x, expr.Constant) and isinstance(biases, expr.Constant):
        return expr.Constant(add_biases_fn.forward([x.value, biases.value])[0])
    else:
        return expr.Apply(add_biases_fn, [x, biases])
Exemple #9
0
def linear(x, weights):
    if isinstance(x, expr.Constant) and isinstance(weights, expr.Constant):
        return expr.Constant(linear_fn.forward([x.value, weights.value])[0])
    else:
        return expr.Apply(linear_fn, [x, weights])
Exemple #10
0
def sigmoid(x):
    if isinstance(x, expr.Constant):
        return expr.Constant(sigmoid_fn.forward([x.value])[0])
    else:
        return expr.Apply(sigmoid_fn, [x])
Exemple #11
0
def concat(args, axis):
    if all(lambda x: isinstance(expr.Constant), args):
        return expr.Constant(
            Concat(axis).forward(map(lambda x: x.value, args)))
    else:
        return expr.Apply(Concat(axis), [args])
Exemple #12
0
def broadcast(x, shape=None):
    if isinstance(x, expr.Constant):
        return expr.Constant(Broadcast(shape).forward([x.value])[0])
    else:
        return expr.Apply(Broadcast(shape), [x])