Commit e82cc5ab by vincent

fixed tinyYolov2 implementation

parent 886cf99e
...@@ -25,22 +25,23 @@ export class TinyYolov2 extends NeuralNetwork<NetParams> { ...@@ -25,22 +25,23 @@ export class TinyYolov2 extends NeuralNetwork<NetParams> {
} }
const out = tf.tidy(() => { const out = tf.tidy(() => {
const batchTensor = input.toBatchTensor(416).div(tf.scalar(255)).toFloat() //const batchTensor = input.toBatchTensor(416).div(tf.scalar(255)).toFloat() as tf.Tensor4D
let out = tf.pad(batchTensor, [[0, 0], [1, 1], [1, 1], [0, 0]]) as tf.Tensor4D // TODO: fix boxes after padding
const batchTensor = tf.image.resizeBilinear(input.inputs[0], [416, 416]).toFloat().div(tf.scalar(255)).expandDims() as tf.Tensor4D
out = convWithBatchNorm(out, params.conv0) let out = convWithBatchNorm(batchTensor, params.conv0)
out = tf.maxPool(out, [2, 2], [2, 2], 'valid') out = tf.maxPool(out, [2, 2], [2, 2], 'same')
out = convWithBatchNorm(out, params.conv1) out = convWithBatchNorm(out, params.conv1)
out = tf.maxPool(out, [2, 2], [2, 2], 'valid') out = tf.maxPool(out, [2, 2], [2, 2], 'same')
out = convWithBatchNorm(out, params.conv2) out = convWithBatchNorm(out, params.conv2)
out = tf.maxPool(out, [2, 2], [2, 2], 'valid') out = tf.maxPool(out, [2, 2], [2, 2], 'same')
out = convWithBatchNorm(out, params.conv3) out = convWithBatchNorm(out, params.conv3)
out = tf.maxPool(out, [2, 2], [2, 2], 'valid') out = tf.maxPool(out, [2, 2], [2, 2], 'same')
out = convWithBatchNorm(out, params.conv4) out = convWithBatchNorm(out, params.conv4)
out = tf.maxPool(out, [2, 2], [2, 2], 'valid') out = tf.maxPool(out, [2, 2], [2, 2], 'same')
out = convWithBatchNorm(out, params.conv5) out = convWithBatchNorm(out, params.conv5)
out = tf.maxPool(out, [2, 2], [1, 1], 'valid') out = tf.maxPool(out, [2, 2], [1, 1], 'same')
out = convWithBatchNorm(out, params.conv6) out = convWithBatchNorm(out, params.conv6)
out = convWithBatchNorm(out, params.conv7) out = convWithBatchNorm(out, params.conv7)
out = convLayer(out, params.conv8, 'valid', false) out = convLayer(out, params.conv8, 'valid', false)
......
...@@ -5,7 +5,8 @@ import { ConvWithBatchNorm } from './types'; ...@@ -5,7 +5,8 @@ import { ConvWithBatchNorm } from './types';
export function convWithBatchNorm(x: tf.Tensor4D, params: ConvWithBatchNorm): tf.Tensor4D { export function convWithBatchNorm(x: tf.Tensor4D, params: ConvWithBatchNorm): tf.Tensor4D {
return tf.tidy(() => { return tf.tidy(() => {
let out = tf.conv2d(x, params.conv.filters, [1, 1], 'valid') let out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]) as tf.Tensor4D
out = tf.conv2d(out, params.conv.filters, [1, 1], 'valid')
out = tf.sub(out, params.bn.sub) out = tf.sub(out, params.bn.sub)
out = tf.mul(out, params.bn.truediv) out = tf.mul(out, params.bn.truediv)
out = tf.add(out, params.conv.bias) out = tf.add(out, params.conv.bias)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment