setup.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env python
  2. import io
  3. import json
  4. import os
  5. import re
  6. import setuptools
  7. import setuptools.command.build_py
  8. import distutils.command.build
  9. node_dependencies = [
  10. ( 'netron', [
  11. 'node_modules/d3/dist/d3.min.js',
  12. 'node_modules/dagre/dist/dagre.min.js',
  13. 'node_modules/marked/marked.min.js',
  14. 'node_modules/pako/dist/pako.min.js' ] )
  15. ]
  16. class build(distutils.command.build.build):
  17. user_options = distutils.command.build.build.user_options + [ ('version', None, 'version' ) ]
  18. def initialize_options(self):
  19. distutils.command.build.build.initialize_options(self)
  20. self.version = None
  21. def finalize_options(self):
  22. distutils.command.build.build.finalize_options(self)
  23. def run(self):
  24. build_py.version = bool(self.version)
  25. return distutils.command.build.build.run(self)
  26. class build_py(setuptools.command.build_py.build_py):
  27. user_options = setuptools.command.build_py.build_py.user_options + [ ('version', None, 'version' ) ]
  28. def initialize_options(self):
  29. setuptools.command.build_py.build_py.initialize_options(self)
  30. self.version = None
  31. def finalize_options(self):
  32. setuptools.command.build_py.build_py.finalize_options(self)
  33. def run(self):
  34. setuptools.command.build_py.build_py.run(self)
  35. for target, files in node_dependencies:
  36. target = os.path.join(self.build_lib, target)
  37. if not os.path.exists(target):
  38. os.makedirs(target)
  39. for file in files:
  40. self.copy_file(file, target)
  41. if build_py.version:
  42. for package, src_dir, build_dir, filenames in self.data_files:
  43. for filename in filenames:
  44. if filename == 'index.html':
  45. filepath = os.path.join(build_dir, filename)
  46. with open(filepath, 'r') as file :
  47. content = file.read()
  48. content = re.sub(r'(<meta name="version" content=")\d+.\d+.\d+(">)', r'\g<1>' + package_version() + r'\g<2>', content)
  49. with open(filepath, 'w') as file:
  50. file.write(content)
  51. def build_module(self, module, module_file, package):
  52. setuptools.command.build_py.build_py.build_module(self, module, module_file, package)
  53. if build_py.version and module == '__version__':
  54. outfile = self.get_module_outfile(self.build_lib, package.split('.'), module)
  55. with open(outfile, 'w+') as file:
  56. file.write("__version__ = '" + package_version() + "'\n")
  57. def package_version():
  58. folder = os.path.realpath(os.path.dirname(__file__))
  59. with open(os.path.join(folder, 'package.json')) as package_file:
  60. package_manifest = json.load(package_file)
  61. return package_manifest['version']
  62. setuptools.setup(
  63. name="netron",
  64. version=package_version(),
  65. description="Viewer for neural network, deep learning and machine learning models",
  66. long_description='Netron is a viewer for neural network, deep learning and machine learning models.\n\n' +
  67. 'Netron supports **ONNX** (`.onnx`, `.pb`, `.pbtxt`), **Keras** (`.h5`, `.keras`), **Core ML** (`.mlmodel`), **Caffe** (`.caffemodel`, `.prototxt`), **Caffe2** (`predict_net.pb`), **Darknet** (`.cfg`), **MXNet** (`.model`, `-symbol.json`), **Barracuda** (`.nn`), **ncnn** (`.param`), **Tengine** (`.tmfile`), **TNN** (`.tnnproto`), **UFF** (`.uff`) and **TensorFlow Lite** (`.tflite`). Netron has experimental support for **TorchScript** (`.pt`, `.pth`), **PyTorch** (`.pt`, `.pth`), **Torch** (`.t7`), **ArmNN** (`.armnn`), **BigDL** (`.bigdl`, `.model`), **Chainer** (`.npz`, `.h5`), **CNTK** (`.model`, `.cntk`), **Deeplearning4j** (`.zip`), **MediaPipe** (`.pbtxt`), **ML.NET** (`.zip`), **MNN** (`.mnn`), **PaddlePaddle** (`.zip`, `__model__`), **OpenVINO** (`.xml`), **scikit-learn** (`.pkl`), **TensorFlow.js** (`model.json`, `.pb`) and **TensorFlow** (`.pb`, `.meta`, `.pbtxt`, `.ckpt`, `.index`).',
  68. keywords=[
  69. 'onnx', 'keras', 'tensorflow', 'tflite', 'coreml', 'mxnet', 'caffe', 'caffe2', 'torchscript', 'pytorch', 'ncnn', 'mnn', 'openvino', 'darknet', 'paddlepaddle', 'chainer',
  70. 'artificial intelligence', 'machine learning', 'deep learning', 'neural network',
  71. 'visualizer', 'viewer'
  72. ],
  73. license="MIT",
  74. cmdclass={
  75. 'build': build,
  76. 'build_py': build_py
  77. },
  78. package_dir={
  79. 'netron': 'source'
  80. },
  81. packages=[
  82. 'netron'
  83. ],
  84. package_data={
  85. 'netron': [
  86. 'favicon.ico', 'icon.png',
  87. 'base.js', 'protobuf.js', 'flatbuffers.js',
  88. 'numpy.js', 'pickle.js', 'hdf5.js', 'bson.js',
  89. 'zip.js', 'tar.js', 'gzip.js',
  90. 'armnn.js', 'armnn-metadata.json', 'armnn-schema.js',
  91. 'bigdl.js', 'bigdl-metadata.json', 'bigdl-proto.js',
  92. 'barracuda.js',
  93. 'caffe.js', 'caffe-metadata.json', 'caffe-proto.js',
  94. 'caffe2.js', 'caffe2-metadata.json', 'caffe2-proto.js',
  95. 'cntk.js', 'cntk-metadata.json', 'cntk-proto.js',
  96. 'coreml.js', 'coreml-metadata.json', 'coreml-proto.js',
  97. 'darknet.js', 'darknet-metadata.json',
  98. 'dl4j.js', 'dl4j-metadata.json',
  99. 'flux.js', 'flux-metadata.json',
  100. 'keras.js', 'keras-metadata.json',
  101. 'mediapipe.js',
  102. 'mlnet.js', 'mlnet-metadata.json',
  103. 'mnn.js', 'mnn-metadata.json', 'mnn-schema.js',
  104. 'mxnet.js', 'mxnet-metadata.json',
  105. 'ncnn.js', 'ncnn-metadata.json',
  106. 'npz.js',
  107. 'tnn.js', 'tnn-metadata.json',
  108. 'onnx.js', 'onnx-metadata.json', 'onnx-proto.js',
  109. 'openvino.js', 'openvino-metadata.json', 'openvino-parser.js',
  110. 'paddle.js', 'paddle-metadata.json', 'paddle-proto.js',
  111. 'pytorch.js', 'pytorch-metadata.json', 'python.js',
  112. 'sklearn.js', 'sklearn-metadata.json',
  113. 'tengine.js', 'tengine-metadata.json',
  114. 'uff.js', 'uff-metadata.json', 'uff-proto.js',
  115. 'tf.js', 'tf-metadata.json', 'tf-proto.js',
  116. 'tflite.js', 'tflite-metadata.json', 'tflite-schema.js',
  117. 'torch.js', 'torch-metadata.json',
  118. 'index.html', 'index.js',
  119. 'view-grapher.css', 'view-grapher.js',
  120. 'view-sidebar.css', 'view-sidebar.js',
  121. 'view.js',
  122. 'server.py'
  123. ]
  124. },
  125. install_requires=[],
  126. author='Lutz Roeder',
  127. author_email='[email protected]',
  128. url='https://github.com/lutzroeder/netron',
  129. entry_points={
  130. 'console_scripts': [ 'netron = netron:main' ]
  131. },
  132. classifiers=[
  133. 'Intended Audience :: Developers',
  134. 'Intended Audience :: Education',
  135. 'Intended Audience :: Science/Research',
  136. 'Programming Language :: Python :: 2',
  137. 'Programming Language :: Python :: 2.7',
  138. 'Programming Language :: Python :: 3',
  139. 'Programming Language :: Python :: 3.6',
  140. 'Topic :: Software Development',
  141. 'Topic :: Software Development :: Libraries',
  142. 'Topic :: Software Development :: Libraries :: Python Modules',
  143. 'Topic :: Scientific/Engineering',
  144. 'Topic :: Scientific/Engineering :: Mathematics',
  145. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  146. 'Topic :: Scientific/Engineering :: Visualization'
  147. ]
  148. )