Quick Start¶
In this section, we would like to show an overview to give a quick start.
Operation¶
There are some operations supported in tednet
, and it is convinient to use them.
[1]:
import tednet as tdt
Create matrix whose diagonal elements are ones
[2]:
diag_matrix = tdt.eye(5, 5)
print(diag_matrix)
tensor([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
Take Pytorch tensor to Numpy narray
[3]:
print(type(diag_matrix))
<class 'torch.Tensor'>
[4]:
diag_matrix = tdt.to_numpy(diag_matrix)
[5]:
print(type(diag_matrix))
<class 'numpy.ndarray'>
Take Numpy narray to Pytorch tensor
[6]:
diag_matrix = tdt.to_tensor(diag_matrix)
[7]:
print(type(diag_matrix))
<class 'torch.Tensor'>
Tensor Decomposition Networks (Tensor Ring for Sample)¶
To use tensor ring decomposition models, simply calling the tensor ring module is enough.
[8]:
import tednet.tnn.tensor_ring as tr
Here, we would like to give a case of building the TR-LeNet5.
[9]:
# Define a TR-LeNet5
model = tr.TRLeNet5(10, [6, 6, 6, 6])
compression_ration is: 0.3968253968253968
compression_ration is: 14.17233560090703
compression_ration is: 241.54589371980677
compression_ration is: 2.867383512544803