I was trying to take tensor from a ConvNet output and use it in another model in TF.js. Is there any way to save a TF tensor to a file ans load that file in TF.js and get the tensor back?
Asked
Active
Viewed 233 times
1
-
https://js.tensorflow.org/api/0.11.2/#loadModel – shrys Jul 05 '19 at 09:10
-
1I have already loaded the model. But the input is a tensor in TF python, I want to use it in TF.js model. I somehow need to extract 32x32x32x32 tensor to TF.js tensor – Suraj Parmar Jul 05 '19 at 09:15
1 Answers
1
A tensor can be saved to a file. However,to load it back a server is required as the browser does not access the file system directly unless using an input type file
.
To save a tensor to a file, the tensor values have to be downloaded first using data
or dataSync
.
const tensor = tf.tensor([1, 2])
// download values
const values = tensor.dataSync()
To see how you can save values
to a file, you can use the following answer
To load back the tensor saved, the file content needs to be served by a server with an http request. Upon receiving the response of the request,
const tensorRetrieved = tf.tensor(contentHttpResponse) // if needed parse the string response using JSON.parse
The other option would be to use tensorflow.js on node. An http request and response would not be needed as node can access the file system.

edkeveked
- 17,989
- 10
- 55
- 93
-
I got the server, However i need a way to save a TensorFlow tensor from python to local disk then to server and from server to browser. However I am unable to save a tensor in python to local disk... – Suraj Parmar Jul 06 '19 at 16:28