Skip to content

Instantly share code, notes, and snippets.

@kedevked
Created February 12, 2021 18:09
Show Gist options
  • Save kedevked/b70fb721026171dfadcca09473890e0e to your computer and use it in GitHub Desktop.
Save kedevked/b70fb721026171dfadcca09473890e0e to your computer and use it in GitHub Desktop.
drawing rectangle using tensorflow.js
<head>
<style>
body {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
canvas {
width: 100vh;
position: absolute;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@2.0.0/dist/tf.min.js"></script>
</head>
<body>
<script>
const tensor = tf.ones([30, 40, 3], 'int32').mul(255).cast('int32');
tensor1 = tensor.pad([[135, 135], [180, 180], [0, 0]], 0)
const canvas1 = document.createElement('canvas');
tf.browser.toPixels(tensor1, canvas1);
document.body.append(canvas1);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment