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.

README.md 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # Load and Run
  2. Load a model and run, for testing/debugging/profiling.
  3. ## Build
  4. *megvii3 build*
  5. ```sh
  6. bazel build //brain/megbrain:load_and_run
  7. ```
  8. See [mnist-example](../mnist-example) for detailed explanations on build.
  9. ## Dump Model
  10. There are two methods to dump model:
  11. 1. Dump by `MegHair/utils/debug/load_network_and_run.py --dump-cpp-model
  12. /path/to/output`, to test on random inputs. Useful for profiling.
  13. 2. Pack model as specified by
  14. [`dump_with_testcase.py`](dump_with_testcase.py), and use
  15. that script to dump model. This is useful for checking correctness on
  16. different platforms.
  17. ### Input File for `dump_with_testcase.py`
  18. The input file must be a python pickle. It can be in one of the following two
  19. formats:
  20. 1. Contain a network that can be loaded by `meghair.utils.io.load_network`; in
  21. such case, `--data` must be given and network output evaulated on current
  22. computing device is used as groundtruth. All output vars would be checked.
  23. The input data can be one of the following:
  24. 1. In the format `var0:file0;var1:file1...` meaning that `var0` should use
  25. image file `file0`, `var1` should use image `file1` and so on. If there
  26. is only one input var, the var name can be omitted. This can be combined
  27. with `--resize-input` option.
  28. 2. In the format `var0:#rand(min, max, shape...);var1:#rand(min, max)...`
  29. meaning to fill the corresponding input vars with uniform random numbers
  30. in the range `[min, max)`, optionally overriding its shape.
  31. 2. Contain a dict in the format `{"outputs": [], "testcases": []}`, where
  32. `outputs` is a list of output `VarNode`s and `testcases` is a list of test
  33. cases. Each test case should be a dict that maps input var names to
  34. corresponding values as `numpy.ndarray`. The expected outputs should also be
  35. provided as inputs, and correctness should be checked by `AssertEqual`. You
  36. can find more details in `dump_with_testcase.py`.
  37. ### Input File for `dump_with_testcase_mge.py`
  38. The input file is obtained by calling `megengine.jit.trace.dump()`.
  39. `--data` must be given.
  40. ## Example
  41. 1. Obtain the model file by running [xornet.py](../../python_module/examples/xor/xornet.py)
  42. 2. Dump the file with test cases attached to the model.
  43. ```
  44. python3 dump_with_testcase_mge.py xornet_deploy.mge -o xornet.mge -d "#rand(0.1, 0.8, 4, 2)"
  45. ```
  46. The dumped file `xornet.mge` can be loaded by `load_and_run`.

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台

Contributors (1)