xref: /aosp_15_r20/external/libopus/dnn/torch/weight-exchange/README.md (revision a58d3d2adb790c104798cd88c8a3aff4fa8b82cc)
1*a58d3d2aSXin Li# weight-exchange
2*a58d3d2aSXin Li
3*a58d3d2aSXin Li
4*a58d3d2aSXin Li
5*a58d3d2aSXin Li## Weight Exchange
6*a58d3d2aSXin LiRepo wor exchanging weights betweeen torch an tensorflow.keras modules, using an intermediate numpy format.
7*a58d3d2aSXin Li
8*a58d3d2aSXin LiRoutines for loading/dumping torch weights are located in exchange/torch and can be loaded with
9*a58d3d2aSXin Li```
10*a58d3d2aSXin Liimport exchange.torch
11*a58d3d2aSXin Li```
12*a58d3d2aSXin Liand routines for loading/dumping tensorflow weights are located in exchange/tf and can be loaded with
13*a58d3d2aSXin Li```
14*a58d3d2aSXin Liimport exchange.tf
15*a58d3d2aSXin Li```
16*a58d3d2aSXin Li
17*a58d3d2aSXin LiNote that `exchange.torch` requires torch to be installed and `exchange.tf` requires tensorflow. To avoid the necessity of installing both torch and tensorflow in the working environment, none of these submodules is imported when calling `import exchange`. Similarly, the requirements listed in `requirements.txt` do include neither Tensorflow or Pytorch.
18*a58d3d2aSXin Li
19*a58d3d2aSXin Li
20*a58d3d2aSXin Li## C export
21*a58d3d2aSXin LiThe module `exchange.c_export` contains routines to export weights to C files. On the long run it will be possible to call all `dump_...` functions with either a path string or a `CWriter` instance based on which the export format is chosen. This is currently only implemented for `torch.nn.GRU`, `torch.nn.Linear` and `torch.nn.Conv1d`.