Version 1.0.0
TF-JS-Storage serves as an extension of tensorflow.js. It offers functions for storing tensors in web storage as well as turning them into strings.
An example of a use case for this extension might be to store a model to later compare it to a different one or to store the training progress of a model to further improve it at a later point in time.
Method 1: Download the tfStorage.js file and import it like this:
<script src="tfStorage.js"></script>
Method 2: Import the project from a CDN like this:
<script src="https://cdn.jsdelivr.net/gh/N-Ziermann/tf-js-storage@1/tfStorage.js"></script>
To store a tensor in local storage you can use the toLocalStorage Function as follows:
toLocalStorage(key, tensor);
To retrieve the tensor from local storage you can then use fromLocalStorage like this:
var tensor = fromLocalStorage(key);
Note: For session storage you'd use the toSessionStorage and fromSessionStorage functions. There's no difference in usage though.
To only convert a tensor into a string and not store it in web storage you'd use tensorToString like this:
var str = tensorToString(tensor);
To then convert it back you'd just need to use stringToTensor like this:
var tensor = stringToTensor(str);
- Niklas Ziermann
© Niklas Ziermann
GNU GPLv3