Esempio n. 1
0
function dropout(x, level, noiseShape, seed) {
    if (noiseShape != null && !_.isEqual(x.shape, noiseShape)) {
        throw new errors_1.NotImplementedError('Non-default noise shape is not implemented yet: ' +
            JSON.stringify(noiseShape));
    }
    if (seed != null) {
        throw new errors_1.NotImplementedError('seed is not implemented for dropout yet.');
    }
    var multiplier = tfc.step(tfc.add(neg(level), randomUniform(x.shape, 0, 1, types_1.DType.float32)));
    multiplier = tfc.mul(divide(getScalar(1), subtract(getScalar(1), level)), multiplier);
    return tfc.mul(x, multiplier);
}
Esempio n. 2
0
function decodeBoxesLayer(x0, x1) {
    var _a = getCenterCoordinatesAndSizesLayer(x0), sizes = _a.sizes, centers = _a.centers;
    var vec = tf.unstack(tf.transpose(x1, [1, 0]));
    var div0_out = tf.div(tf.mul(tf.exp(tf.div(vec[2], tf.scalar(5))), sizes[0]), tf.scalar(2));
    var add0_out = tf.add(tf.mul(tf.div(vec[0], tf.scalar(10)), sizes[0]), centers[0]);
    var div1_out = tf.div(tf.mul(tf.exp(tf.div(vec[3], tf.scalar(5))), sizes[1]), tf.scalar(2));
    var add1_out = tf.add(tf.mul(tf.div(vec[1], tf.scalar(10)), sizes[1]), centers[1]);
    return tf.transpose(tf.stack([
        tf.sub(add0_out, div0_out),
        tf.sub(add1_out, div1_out),
        tf.add(add0_out, div0_out),
        tf.add(add1_out, div1_out)
    ]), [1, 0]);
}
Esempio n. 3
0
function sigmoidCrossEntropyWithLogits(target, output) {
    var maxOutput = tfc.maximum(output, tfc.zerosLike(output));
    var outputXTarget = tfc.mul(output, target);
    var sigmoidOutput = tfc.log(tfc.add(getScalar(1), tfc.exp(tfc.neg(tfc.abs(output)))));
    var result = tfc.add(tfc.sub(maxOutput, outputXTarget), sigmoidOutput);
    return result;
}
Esempio n. 4
0
function categoricalCrossentropy(target, output, fromLogits) {
    if (fromLogits === void 0) { fromLogits = false; }
    if (fromLogits) {
        output = softmax(output);
    }
    else {
        var outputSum = sum(output, shape(output).length - 1, true);
        output = divide(output, outputSum);
    }
    output = clip(output, exports.epsilon(), 1 - exports.epsilon());
    return tfc.neg(tfc.sum(tfc.mul(target, tfc.log(output)), shape(output).length - 1));
}
Esempio n. 5
0
function scalarTimesArray(c, x) {
    return tfc.mul(c, x);
}
Esempio n. 6
0
function multiply(x, y) {
    return tfc.mul(x, y);
}