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
template <typename T> | |
std::vector<T> operator+(std::vector<T> v1, std::vector<T> v2) | |
{ | |
std::vector<T> v; | |
auto itr1 = v1.begin(); | |
auto itr2 = v2.begin(); | |
for (; itr1 < v1.end(); itr1++, itr2++) | |
{ | |
v.push_back(*itr1 + *itr2); | |
} |
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
template <typename T> | |
double square(T elem) | |
{ | |
return elem * elem; | |
} |
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
// https://medium.com/@aniketbiprojit/c-expression-templates-for-optimized-compile-time-evaluation-aff817de04ee | |
double square(int elem){ | |
return elem*elem; | |
} | |
double square(double elem){ | |
return elem*elem; | |
} |
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
import os | |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' | |
import tensorflow as tf | |
import tensorflow.keras as keras | |
# import tensorflow_federated as tff | |
from tensorflow_federated.python.tensorflow_libs import tensor_utils | |
from tensorflow_federated.python.learning.framework import optimizer_utils |
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
const { exec } = require('child_process') | |
const fs = require('fs') | |
model_dirs = fs.readdirSync(`${__dirname}/tfjs-models`) | |
if (!fs.existsSync('keras_models')) fs.mkdirSync('keras_models') | |
model_dirs.forEach((dir) => { | |
exec( | |
`tensorflowjs_converter --input_format tfjs_layers_model tfjs-models/${dir}/model.json keras_models/${dir}.h5 --output_format keras_saved_model` |
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
const cluster = require('cluster') | |
const os = require('os') | |
const numCPUs = os.cpus().length | |
const tf = require('@tensorflow/tfjs-node') | |
if (cluster.isMaster) { | |
console.log(X[0]) | |
console.log(y[0], y[1]) |
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
const run = async (X_tensor,y_tensor,revision) => { | |
const model = await load_model() | |
model.fit(X_tensor, y_tensor, { | |
epochs: 10, | |
batchSize: 32, | |
callbacks: { onBatchEnd }, | |
}) | |
.then((info) => { | |
console.log('Final accuracy', info.history.acc) | |
}) |
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
const load_data = require('./data_loader') | |
const data = load_data() | |
const X = data.map((elem) => { | |
const key = Object.keys(elem)[0] | |
return elem[key].map((val) => val / 255) | |
}) | |
console.log(X[0]) | |
const arr = Array.apply(null, Array(10)).map(() => 0) |
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
const tf = require('@tensorflow/tfjs-node') | |
const load_model = async () => { | |
const model = await tf.loadLayersModel( | |
'file:///path/to/directory/tfjs/model.json' | |
) | |
model.weights.forEach((w) => { | |
console.log(w.name, w.shape) | |
}) |
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
// Code from https://stackoverflow.com/questions/25024179/reading-mnist-dataset-with-javascript-node-js | |
// Author https://stackoverflow.com/users/254532/lilleman | |
// Download files from http://yann.lecun.com/exdb/mnist/ | |
const fs = require('fs') | |
const dataFileBuffer = fs.readFileSync(__dirname + '/train-images-idx3-ubyte') | |
const labelFileBuffer = fs.readFileSync(__dirname + '/train-labels-idx1-ubyte') | |
const load = () => { | |
let pixelValues = [] |
NewerOlder