I have a 3-dimensional tensor that I create outside of my python code and am able to encode in any human-readable format. I need to load the values of this tensor as a frozen layer to my pytorch
NN. I've tried to encode the tensor as a text file in the form [[[a,b],[c,d]], [[e,f], [g,h]], [[k,l],[m,n]]]
which seemed to be the most logical way for that. Then I tried to read its value via
tensor = torch.from_numpy(np.loadtxt("./arrays/tensor.txt"))
but got the exception in npyio.py
ValueError: could not convert string to float: '[[[-2.888356,'
Apparently, that's not how it works and the values are to be written as plain numbers separated by spaces and \n
, but then I don't see how to easily read the data of dimension >= 2 with numpy
.
What could be other simple methods to write down and read the tensor value into a pytorch
tensor?