Skip to content

Commit

Permalink
Moved vscode settings to root, and a basic package.json
Browse files Browse the repository at this point in the history
* Removed superfluous comments and timings
* Added .gitignore to ignore the bundle.js
* ignoring yarn-error.log
* updated readme to have proper instructions for installing
* changed display style
  • Loading branch information
oveddan committed Apr 6, 2018
1 parent d60f2f9 commit 17cf5d0
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 3,725 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
**/*/node_modules
**/*/coverage
**/*/dist
**/*/dist
**/*/yarn-error.log
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"clang-format": "~1.2.2"
},
"license": "Apache-2.0"
}
16 changes: 15 additions & 1 deletion posenet/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
# PoseNet model

This package contains a standalone PoseNet model for Pose Estimation,
This package contains a standalone PoseNet for Pose Estimation,
as well as some demos.

## Installation

You can use this as standalone es5 bundle like this:

```html
<script src="https://unpkg.com/tfjs-posenet"></script>
```

Or you can install it via npm for use in a TypeScript / ES6 project.

```sh
npm install tfjs-posenet --save-dev
```

## Setup

### Developing the Demos
Expand Down
1 change: 1 addition & 0 deletions posenet/demos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bundle.js
15 changes: 3 additions & 12 deletions posenet/demos/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ function detectPoseInRealTime(video: HTMLVideoElement, model: posenet.PoseNet) {
const ctx = canvas.getContext('2d');

async function poseDetectionFrame() {
const start = new Date().getTime();
const videoResolution = Number(guiState.videoResolution);
const outputStride = Number(guiState.outputStride) as 8 | 16 | 32;
const minConfidence = Number(guiState.minPartConfidence);
Expand All @@ -159,8 +158,6 @@ function detectPoseInRealTime(video: HTMLVideoElement, model: posenet.PoseNet) {

const scale = outputResolution / videoResolution;

const startPredict = new Date().getTime();

const poses = await model.estimateMultiplePoses(
image,
outputStride,
Expand All @@ -169,10 +166,6 @@ function detectPoseInRealTime(video: HTMLVideoElement, model: posenet.PoseNet) {
guiState.nmsRadius,
);

console.log(
'total prediction and decode time',
new Date().getTime() - startPredict);

if (guiState.showVideo) {
const toRender = await tf.tidy(
() => originalImage.reverse(1).resizeBilinear(
Expand All @@ -193,11 +186,9 @@ function detectPoseInRealTime(video: HTMLVideoElement, model: posenet.PoseNet) {
}
});

console.log('after render models in memory', tf.memory().numTensors);

image.dispose();
originalImage.dispose();
console.log('frame time', new Date().getTime() - start);

requestAnimationFrame(poseDetectionFrame);
}

Expand All @@ -209,8 +200,8 @@ export async function bindPage() {

await model.load();

document.getElementById('loading').setAttribute('style', 'display:none');
document.getElementById('main').setAttribute('style', 'display:block');
document.getElementById('loading').style.display = 'none';
document.getElementById('main').style.display = 'block';

const cameras = await getCameras();
if (cameras.length === 0) {
Expand Down
15 changes: 7 additions & 8 deletions posenet/demos/coco.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,10 @@ function drawResults(
String(outputStride);
resultsElement.querySelector('.inference').innerHTML =
`Inference time: ${inferenceTime} ms`;
// console.log(pOutputStridex2d(heatmaps).print())

drawHeatmapAsAlpha(image, heatmaps, outputStride, resultsCanvas);

poses.forEach(pose => {
console.log('score', pose.score, minPartConfidence);
if (pose.score >= minPoseConfidence) {
drawKeypoints(
pose.keypoints, minPartConfidence, resultsCanvas.getContext('2d'));
Expand Down Expand Up @@ -186,26 +185,26 @@ async function testImageForSinglePoseClick(
model: posenet.PoseNet, image: string, guiState: GuiState) {
setStatusText('Predicting...');

document.getElementById('results').setAttribute('style', 'display:none');
document.getElementById('results').style.display = 'none';

await testImageForSinglePoseAndDrawResults(model, image, guiState);

setStatusText('');

document.getElementById('results').setAttribute('style', 'display:block');
document.getElementById('results').style.display = 'block';
}

async function testImageForMultiPoseClick(
model: posenet.PoseNet, image: string, guiState: GuiState) {
setStatusText('Predicting...');

document.getElementById('results').setAttribute('style', 'display:none');
document.getElementById('results').style.display = 'none';

await testImageForMultiplePosesAndDrawResults(model, image, guiState);

setStatusText('');

document.getElementById('results').setAttribute('style', 'display:block');
document.getElementById('results').style.display = 'block';
}

type MultiPoseDetectionState = {
Expand Down Expand Up @@ -277,6 +276,6 @@ export async function bindPage() {

setupGui(model);

document.getElementById('loading').setAttribute('style', 'display:none');
document.getElementById('main').setAttribute('style', 'display:block');
document.getElementById('loading').style.display = 'none';
document.getElementById('main').style.display = 'block';
}
1 change: 0 additions & 1 deletion posenet/demos/demo_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export function drawSkeleton(
posenet.getAdjacentKeyPoints(keypoints, minConfidence);

adjacentKeyPoints.forEach((keypoints: Keypoint[]) => {
// console.log('in draw', leftPoint, rightPoint)
drawSegment(
toTuple(keypoints[0].point), toTuple(keypoints[1].point), '#0000ff',
scale, ctx);
Expand Down
10 changes: 4 additions & 6 deletions posenet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@types/jasmine": "~2.5.53",
"browserify": "~14.5.0",
"browserify-shim": "~3.8.14",
"clang-format": "~1.2.2",
"dat.gui": "^0.7.1",
"jasmine-core": "~2.6.4",
"karma": "~1.7.0",
Expand All @@ -35,19 +34,18 @@
"watchify": "~3.11.0"
},
"scripts": {
"prep": "yarn && mkdirp dist",
"build": "tsc --sourceMap false && browserify -g browserify-shim --standalone posenet src/index.ts -p [tsify] -o dist/bundle.js",
"test": "karma start",
"deploy-demo": "cd demos/ && gcloud app deploy -v cl-deeplearnjs-posenet --project cl-move-mirror --no-promote",
"publish-npm": "tsc --sourceMap false && yarn build && npm publish",
"build-demo": "browserify --debug --standalone demos demos/index.ts -p [tsify] -o demos/bundle.js",
"deploy-demo": "cd demos/ && gcloud app deploy -v cl-deeplearnjs-posenet --project cl-move-mirror --no-promote",
"watch-demo": "watchify --debug -v --standalone demos demos/index.ts -p [tsify] -o demos/bundle.js",
"simple-server": "cd demos && python -m SimpleHTTPServer",
"dev": "npm run watch-demo & npm run simple-server",
"lint": "tslint -p . -t verbose",
"publish-npm": "tsc --sourceMap false && yarn build && npm publish"
"lint": "tslint -p . -t verbose"
},
"browserify-shim": {
"deeplearn": "global:dl"
"tfjs": "global:dl"
},
"browserify": {
"global-transform": [
Expand Down
Loading

0 comments on commit 17cf5d0

Please sign in to comment.