Skip to content

Commit c493d1f

Browse files
last fixes for architecture
1 parent 45c9d6f commit c493d1f

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

src/faceDetectionNet/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export function faceDetectionNet(weights: Float32Array) {
6767
})
6868
}
6969

70-
// TODO debug output
7170
function forward(input: ImageData|ImageData[]|number[]) {
7271
return tf.tidy(
7372
() => forwardTensor(getImgTensor(input))
@@ -100,10 +99,10 @@ export function faceDetectionNet(weights: Float32Array) {
10099
.map(({ score, idx }) => ({
101100
score,
102101
box: {
103-
left: Math.max(0, width * boxes.get(idx, 0)),
104-
right: Math.min(width, width * boxes.get(idx, 1)),
105-
top: Math.max(0, height * boxes.get(idx, 2)),
106-
bottom: Math.min(height, height * boxes.get(idx, 3))
102+
top: Math.max(0, height * boxes.get(idx, 0)),
103+
left: Math.max(0, width * boxes.get(idx, 1)),
104+
bottom: Math.min(height, height * boxes.get(idx, 2)),
105+
right: Math.min(width, width * boxes.get(idx, 3))
107106
}
108107
}))
109108

src/faceDetectionNet/mobileNetV1.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function depthwiseConvLayer(
2121
params.batch_norm_scale,
2222
params.batch_norm_offset
2323
)
24-
return tf.relu(out)
24+
return tf.clipByValue(out, 0, 6)
2525

2626
})
2727
}
@@ -35,6 +35,7 @@ export function mobileNetV1(x: tf.Tensor4D, params: FaceDetectionNet.MobileNetV1
3535

3636
let conv11 = null
3737
let out = pointwiseConvLayer(x, params.conv_0_params, [2, 2])
38+
3839
params.conv_pair_params.forEach((param, i) => {
3940
const layerIdx = i + 1
4041
const depthwiseConvStrides = getStridesForLayerIdx(layerIdx)

src/faceDetectionNet/outputLayer.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ function decodeBoxesLayer(x0: tf.Tensor2D, x1: tf.Tensor2D) {
3030
const vec = tf.unstack(tf.transpose(x1, [1, 0]))
3131

3232
const div0_out = tf.div(tf.mul(tf.exp(tf.div(vec[2], tf.scalar(5))), sizes[0]), tf.scalar(2))
33-
const add0_out = tf.add(tf.mul(tf.exp(tf.div(vec[0], tf.scalar(10))), sizes[0]), centers[0])
33+
const add0_out = tf.add(tf.mul(tf.div(vec[0], tf.scalar(10)), sizes[0]), centers[0])
3434

3535
const div1_out = tf.div(tf.mul(tf.exp(tf.div(vec[3], tf.scalar(5))), sizes[1]), tf.scalar(2))
36-
const add1_out = tf.add(tf.mul(tf.exp(tf.div(vec[1], tf.scalar(10))), sizes[1]), centers[1])
36+
const add1_out = tf.add(tf.mul(tf.div(vec[1], tf.scalar(10)), sizes[1]), centers[1])
3737

3838
return tf.transpose(
3939
tf.stack([
40-
tf.sub(div0_out, add0_out),
41-
tf.sub(div1_out, add1_out),
42-
tf.add(div0_out, add0_out),
43-
tf.add(div1_out, add1_out)
40+
tf.sub(add0_out, div0_out),
41+
tf.sub(add1_out, div1_out),
42+
tf.add(add0_out, div0_out),
43+
tf.add(add1_out, div1_out)
4444
]),
4545
[1, 0]
4646
)

src/faceDetectionNet/pointwiseConvLayer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function pointwiseConvLayer(
1111

1212
let out = tf.conv2d(x, params.filters, strides, 'same')
1313
out = tf.add(out, params.batch_norm_offset)
14-
return tf.relu(out)
14+
return tf.clipByValue(out, 0, 6)
1515

1616
})
1717
}

0 commit comments

Comments
 (0)