human/src/body/modelBase.js

33 lines
889 B
JavaScript
Raw Normal View History

2020-11-18 14:26:28 +01:00
import * as tf from '../../dist/tfjs.esm.js';
2020-10-12 01:22:43 +02:00
class BaseModel {
constructor(model, outputStride) {
this.model = model;
this.outputStride = outputStride;
}
predict(input) {
return tf.tidy(() => {
const asFloat = this.preprocessInput(input.toFloat());
const asBatch = asFloat.expandDims(0);
const results = this.model.predict(asBatch);
const results3d = results.map((y) => y.squeeze([0]));
const namedResults = this.nameOutputResults(results3d);
return {
heatmapScores: namedResults.heatmap.sigmoid(),
offsets: namedResults.offsets,
displacementFwd: namedResults.displacementFwd,
displacementBwd: namedResults.displacementBwd,
};
});
}
/**
* Releases the CPU and GPU memory allocated by the model.
*/
dispose() {
this.model.dispose();
}
}
exports.BaseModel = BaseModel;