You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

convert.py 547 B

123456789101112131415161718192021222324252627282930
  1. # Copyright 2021 Tencent
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. import pnnx
  4. import torch
  5. import torch.nn as nn
  6. import torch.nn.functional as F
  7. class Model(nn.Module):
  8. def __init__(self):
  9. super(Model, self).__init__()
  10. def forward(self, x):
  11. x = F.relu(x)
  12. return x
  13. if __name__ == "__main__":
  14. net = Model()
  15. net.eval()
  16. torch.manual_seed(0)
  17. x = torch.rand(1, 16)
  18. a0 = net(x)
  19. mod = torch.jit.trace(net, x)
  20. mod.save("test_F_relu.pt")
  21. pnnx.convert("test_F_relu.pt", [1, 16], "f32")