Create exe file

Can I collapse my neural network into an exe file and run it as a separate process?

1 Like

What do you mean by that? Do you want to pack your net into .exe file that takes i.e. a path to an image and as an output gives the prediction?

Yes.
Is this really possible?

Yes, try using PyInstaller.

You can try to do this yourself, and if something won’t work, you can learn from my mistakes:

  1. To use it with conda, you have to have pytorch installed from pip under conda, not pure conda
  2. If you are using jsonschema package, use v. 2.6.0, not later
  3. For me it only worked with additional import to PyInstaller:
pyinstaller --hiddenimport pywt._extensions._cwt myScript.py
  1. Also I had to make additional hook for skimage (idk, if you are using that package, if you do, this will help you):
    3.1 - make folder hooks in folder containing your script
    3.2 - make script in that folder that contains:
from PyInstaller.utils.hooks import collect_data_files, collect_submodules

datas = collect_data_files("skimage.io._plugins")
hiddenimports = collect_submodules('skimage.io._plugins')

3.3 add the folder to the command:

pyinstaller --hiddenimport pywt._extensions._cwt --additional-hooks-dir=./hooks myScript.py

3 You can also exclude large unused packages to reduce .exe file size:

pyinstaller --hiddenimport pywt._extensions._cwt --additional-hooks-dir=./hooks --exclude-module matplotlib --exclude-module PyQt5 myScript.py
  1. If you want to make it really one file you can add --onefile to the command
3 Likes

HI mmisiur,

I have been trying to run pytorch as well as an exe and the executable gives me the following error:

File “site-packages\flask\app.py”, line 2447, in wsgi_app
File “site-packages\flask\app.py”, line 1952, in full_dispatch_request
File “site-packages\flask\app.py”, line 1821, in handle_user_exception
File “site-packages\flask_compat.py”, line 39, in reraise
File “site-packages\flask\app.py”, line 1950, in full_dispatch_request
File “site-packages\flask\app.py”, line 1936, in dispatch_request
File “pytorchVizTool\flaskr\ModelServer.py”, line 95, in GeneratePredsForFile
File “pytorchVizTool\flaskr\ModelServer.py”, line 95, in
File “pytorchVizTool\flaskr\FasterRCNN.py”, line 100, in predict
File “pytorchVizTool\flaskr\FasterRCNN.py”, line 142, in get_bounding_box_prediction
File “site-packages\torch\nn\modules\module.py”, line 550, in call
File “site-packages\torchvision\models\detection\generalized_rcnn.py”, line 70, in forward
File “site-packages\torch\nn\modules\module.py”, line 550, in call
File “site-packages\torchvision\models\detection\rpn.py”, line 488, in forward
File “site-packages\torchvision\models\detection\rpn.py”, line 410, in filter_proposals
File “site-packages\torchvision\ops\boxes.py”, line 75, in batched_nms
File “site-packages\torchvision\ops\boxes.py”, line 35, in nms
File “site-packages\torch_ops.py”, line 61, in getattr
RuntimeError: No such operator torchvision::nms

do you have any idea how i could fix this