Skip to content

Instantly share code, notes, and snippets.

View ntakouris's full-sized avatar
🤖
Building robots

Theodoros Ntakouris ntakouris

🤖
Building robots
View GitHub Profile
def serialize_example(feature0, feature1, feature2, feature3):
"""
Creates a tf.train.Example message ready to be written to a file.
"""
# Create a dictionary mapping the feature name to the tf.train.Example-compatible
# data type.
feature = {
'feature0': _int64_feature(feature0),
'feature1': _int64_feature(feature1),
'feature2': _bytes_feature(feature2),
import tensorflow_transform as tft
def preprocessing_fn(inputs):
"""Preprocess input columns into transformed columns."""
x = inputs['x']
y = inputs['y']
s = inputs['s']
x_centered = x - tft.mean(x)
y_normalized = tft.scale_to_0_1(y)
s_integerized = tft.compute_and_apply_vocabulary(s)
async function toggleAction(action) {
setActionText(action)
switch(action) {
case 'jump':
console.log('jump')
var e = new KeyboardEvent('keydown',{'keyCode':32, 'which':32});
document.dispatchEvent(e);
break;
case 'crouch':
var e = new KeyboardEvent('keydown',{'keyCode':40, 'which':40});
h = imageElement.height
pos = h - hip.position.y;
if (pos < h * 0.2) {
toggleAction('crouch')
} else if (pos < h * 0.7) {
toggleAction('idle')
} else {
toggleAction('jump')
}
async function poseHandler(pose) {
l_hip = pose.keypoints[11];
r_hip = pose.keypoints[12];
hip = undefined;
if (l_hip && !r_hip) {
hip = l_hip;
}else if (r_hip && !l_hip) {
hip = r_hip;
}else{
var recording = true;
imageElement.onclick = function() {
recording = !recording;
console.log('recording: ' + recording);
};
var imageElement = document.getElementById('webcam');
imageElement.width = 640 // css is not enough for h/w
imageElement.height = 480 // add those here so that posenet produces non-zero outputs
async function poseHandler(pose) {
// do stuff
}
imageElement.addEventListener('loadeddata', async (event) => {
const net = await posenet.load()
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/posenet"></script>
=== quantizable_default_no_regularizer ===
threshold = 0
32 bits => 0.9137 top5_acc
4 bits => 0.9155 top5_acc
3 bits => 0.9146 top5_acc
2 bits => 0.9123 top5_acc
threshold = 1e-06
32 bits => 0.9137 top5_acc
4 bits => 0.9155 top5_acc
def uniform_q(x, bits=32):
if bits == 32:
return x
n = float(2 ** bits)
out = np.clip(np.round(x * n - 0.5), 0, n-1) / (n-1)
return out
def quantize_weights(x, bits=32):
if bits == 32: