Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support for Pose models from Teachable Machine
Teachable Machine requires TFJS v1, where the rest of ML4K uses TFJS v2, so I'm moving the pose model support to a separate iframe so I can run it on-demand. Signed-off-by: Dale Lane <dale.lane@uk.ibm.com>
- Loading branch information
Showing
7 changed files
with
58 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<html> | ||
<head> | ||
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.3.1/dist/tf.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/pose@0.8/dist/teachablemachine-pose.min.js"></script> | ||
<script type="text/javascript"> | ||
const posemodels = {}; | ||
|
||
function initModel(id, modelurl, metadataurl) { | ||
return tmPose.load(modelurl, metadataurl) | ||
.then(function (model) { | ||
posemodels[id] = model; | ||
}); | ||
} | ||
|
||
function predict(id, imageelem) { | ||
return posemodels[id].estimatePose(imageelem) | ||
.then(function (resp) { | ||
return posemodels[id].predict(resp.posenetOutput); | ||
}) | ||
.then(function (output) { | ||
return output.map(function (tmitem) { | ||
return { | ||
class_name : tmitem.className, | ||
confidence : 100 * tmitem.probability | ||
}; | ||
}); | ||
}); | ||
} | ||
|
||
function createImage(b64imagedata, callback) { | ||
const imageElement = document.createElement('img'); | ||
imageElement.width = 257; | ||
imageElement.height = 257; | ||
imageElement.onload = function () { | ||
callback(imageElement); | ||
}; | ||
imageElement.src = 'data:image/jpeg;base64,' + b64imagedata; | ||
} | ||
</script> | ||
</head> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters