Skip to content

Instantly share code, notes, and snippets.

View SkalskiP's full-sized avatar
👨‍💻
I open-source stuff

Piotr Skalski SkalskiP

👨‍💻
I open-source stuff
View GitHub Profile
@SkalskiP
SkalskiP / make_prediction.js
Created May 16, 2018 16:15
making predictions based on image data
protected async predict(imageData: ImageData) {
const pred = await tf.tidy(() => {
let img:any = tf.fromPixels(imageData, 1);
img = img.reshape([1, 28, 28, 1]);
img = tf.cast(img, 'float32');
const output = this.model.predict(img) as any;
@SkalskiP
SkalskiP / loading_model.js
Created May 15, 2018 23:30
Loading the model to the application
import * as tf from '@tensorflow/tfjs';
// Definition of the component supporting the model
// ...
protected async loadModel() {
this.model = await tf.loadModel(AppSettings.mnistModelUrl);
}
@SkalskiP
SkalskiP / saving_model.sh
Last active May 16, 2018 16:09
saving trained Python model in from readable by TensorFlow.js
$ tensorflowjs_converter --input_format keras ./ModelPY/model.h5 ./../ModelJS
@SkalskiP
SkalskiP / saving_model.py
Last active May 15, 2018 22:29
saving trained Python model in from readable by TensorFlow.js
import tensorflowjs as tfjs
# creating and training of model using Keras
# ...
tfjs.converters.save_keras_model(model, './ModelJS')