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.

test_convnext_tiny.py 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Tencent is pleased to support the open source community by making ncnn available.
  2. #
  3. # Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
  4. #
  5. # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. # in compliance with the License. You may obtain a copy of the License at
  7. #
  8. # https://opensource.org/licenses/BSD-3-Clause
  9. #
  10. # Unless required by applicable law or agreed to in writing, software distributed
  11. # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. # CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. # specific language governing permissions and limitations under the License.
  14. import torch
  15. import torchvision
  16. import torchvision.models as models
  17. from packaging import version
  18. def test():
  19. if version.parse(torchvision.__version__) < version.parse('0.12'):
  20. return True
  21. net = models.convnext_tiny()
  22. net.eval()
  23. torch.manual_seed(0)
  24. x = torch.rand(1, 3, 224, 224)
  25. a = net(x)
  26. # export torchscript
  27. mod = torch.jit.trace(net, x)
  28. mod.save("test_convnext_tiny.pt")
  29. # torchscript to pnnx
  30. import os
  31. os.system("../src/pnnx test_convnext_tiny.pt inputshape=[1,3,224,224]")
  32. # pnnx inference
  33. import test_convnext_tiny_pnnx
  34. b = test_convnext_tiny_pnnx.test_inference()
  35. return torch.allclose(a, b, 1e-4, 1e-4)
  36. if __name__ == "__main__":
  37. if test():
  38. exit(0)
  39. else:
  40. exit(1)