Skip to content

Commit

Permalink
fix gpu mode CAM
Browse files Browse the repository at this point in the history
  • Loading branch information
transcranial committed Nov 27, 2017
1 parent 9d37d68 commit 26ec11e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/visualizations/CAM.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export default class CAM {
}
const matVec = new Tensor([], [this.shape[0] * this.shape[1]])
gemv(1, this.featureMaps.tensor, this.weights.tensor, 1, matVec.tensor)
ops.divseq(matVec.tensor, ops.sum(this.weights.tensor))
this.output.replaceTensorData(matVec.tensor.data)
} else {
if (!this.output) {
Expand Down
16 changes: 6 additions & 10 deletions src/webgl/dynamic/visualizations/cam.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ void main() {
int featureMapsRow = out_x + ${outputShape[0]} * out_y;
float f_sum = 0.;
float w_sum = 0.;
float sum = 0.;
for (int k = 0; k < ${numFeatures}; ++k) {
float f = texelFetch(featureMaps, ivec2(k, featureMapsRow), 0).r;
float w = texelFetch(weights, ivec2(k, 0), 0).r;
f_sum += f * w;
w_sum += w;
sum += f * w;
}
outColor = vec4(max(f_sum / w_sum, 0.0));
outColor = vec4(max(sum, 0.0));
}
`
} else {
Expand All @@ -56,16 +54,14 @@ void main() {
int out_y = int(float(${outputShape[0]}) * outTex.y);
int out_x = int(float(${outputShape[1]}) * outTex.x);
float f_sum = 0.;
float w_sum = 0.;
float sum = 0.;
for (int k = 0; k < ${numFeatures}; ++k) {
float f = texelFetch(featureMaps, ivec2(k, out_y), 0).r;
float w = texelFetch(weights, ivec2(out_x, k), 0).r;
f_sum += f * w;
w_sum += w;
sum += f * w;
}
outColor = vec4(max(f_sum / w_sum, 0.0));
outColor = vec4(max(sum, 0.0));
}
`
}
Expand Down

0 comments on commit 26ec11e

Please sign in to comment.