Skip to content

Commit e82cc5a

Browse files
fixed tinyYolov2 implementation
1 parent 886cf99 commit e82cc5a

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/tinyYolov2/TinyYolov2.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,23 @@ export class TinyYolov2 extends NeuralNetwork<NetParams> {
2525
}
2626

2727
const out = tf.tidy(() => {
28-
const batchTensor = input.toBatchTensor(416).div(tf.scalar(255)).toFloat()
28+
//const batchTensor = input.toBatchTensor(416).div(tf.scalar(255)).toFloat() as tf.Tensor4D
2929

30-
let out = tf.pad(batchTensor, [[0, 0], [1, 1], [1, 1], [0, 0]]) as tf.Tensor4D
30+
// TODO: fix boxes after padding
31+
const batchTensor = tf.image.resizeBilinear(input.inputs[0], [416, 416]).toFloat().div(tf.scalar(255)).expandDims() as tf.Tensor4D
3132

32-
out = convWithBatchNorm(out, params.conv0)
33-
out = tf.maxPool(out, [2, 2], [2, 2], 'valid')
33+
let out = convWithBatchNorm(batchTensor, params.conv0)
34+
out = tf.maxPool(out, [2, 2], [2, 2], 'same')
3435
out = convWithBatchNorm(out, params.conv1)
35-
out = tf.maxPool(out, [2, 2], [2, 2], 'valid')
36+
out = tf.maxPool(out, [2, 2], [2, 2], 'same')
3637
out = convWithBatchNorm(out, params.conv2)
37-
out = tf.maxPool(out, [2, 2], [2, 2], 'valid')
38+
out = tf.maxPool(out, [2, 2], [2, 2], 'same')
3839
out = convWithBatchNorm(out, params.conv3)
39-
out = tf.maxPool(out, [2, 2], [2, 2], 'valid')
40+
out = tf.maxPool(out, [2, 2], [2, 2], 'same')
4041
out = convWithBatchNorm(out, params.conv4)
41-
out = tf.maxPool(out, [2, 2], [2, 2], 'valid')
42+
out = tf.maxPool(out, [2, 2], [2, 2], 'same')
4243
out = convWithBatchNorm(out, params.conv5)
43-
out = tf.maxPool(out, [2, 2], [1, 1], 'valid')
44+
out = tf.maxPool(out, [2, 2], [1, 1], 'same')
4445
out = convWithBatchNorm(out, params.conv6)
4546
out = convWithBatchNorm(out, params.conv7)
4647
out = convLayer(out, params.conv8, 'valid', false)

src/tinyYolov2/convWithBatchNorm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { ConvWithBatchNorm } from './types';
55

66
export function convWithBatchNorm(x: tf.Tensor4D, params: ConvWithBatchNorm): tf.Tensor4D {
77
return tf.tidy(() => {
8-
let out = tf.conv2d(x, params.conv.filters, [1, 1], 'valid')
8+
let out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]) as tf.Tensor4D
9+
out = tf.conv2d(out, params.conv.filters, [1, 1], 'valid')
910
out = tf.sub(out, params.bn.sub)
1011
out = tf.mul(out, params.bn.truediv)
1112
out = tf.add(out, params.conv.bias)

0 commit comments

Comments
 (0)