Create exe file

username: slavavs
cooked: <p>Can I collapse my neural network into an exe file and run it as a separate process?</p>

username: mmisiur
cooked: <p>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?</p>

username: slavavs
cooked: <p>Yes.<br>
Is this really possible?</p>

username: mmisiur
cooked: <p>Yes, try using PyInstaller.</p>
<p>You can try to do this yourself, and if something won’t work, you can learn from my mistakes:</p>
<ol>
<li>To use it with conda, you have to have pytorch installed from pip under conda, not pure conda</li>
<li>If you are using jsonschema package, use v. 2.6.0, not later</li>
<li>For me it only worked with additional import to PyInstaller:</li>
</ol>
<pre><code class="lang-auto">pyinstaller --hiddenimport pywt._extensions._cwt myScript.py
</code></pre>
<ol start="3">
<li>Also I had to make additional hook for skimage (idk, if you are using that package, if you do, this will help you):<br>
3.1 - make folder <code>hooks</code> in folder containing your script<br>
3.2 - make script in that folder that contains:</li>
</ol>
<pre><code class="lang-auto">from PyInstaller.utils.hooks import collect_data_files, collect_submodules

datas = collect_data_files("skimage.io._plugins")
hiddenimports = collect_submodules('skimage.io._plugins')
</code></pre>
<p>3.3 add the folder to the command:</p>
<pre><code class="lang-auto">pyinstaller --hiddenimport pywt._extensions._cwt --additional-hooks-dir=./hooks myScript.py
</code></pre>
<p>3 You can also exclude large unused packages to reduce .exe file size:</p>
<pre><code class="lang-auto">pyinstaller --hiddenimport pywt._extensions._cwt --additional-hooks-dir=./hooks --exclude-module matplotlib --exclude-module PyQt5 myScript.py
</code></pre>
<ol start="4">
<li>If you want to make it really one file you can add <code>--onefile</code> to the command</li>
</ol>

username: Karim_Hasebou
cooked: <p>HI mmisiur,</p>
<p>I have been trying to run pytorch as well as an exe and the executable gives me the following error:</p>
<p>File “site-packages\flask\app.py”, line 2447, in wsgi_app<br>
File “site-packages\flask\app.py”, line 1952, in full_dispatch_request<br>
File “site-packages\flask\app.py”, line 1821, in handle_user_exception<br>
File “site-packages\flask_compat.py”, line 39, in reraise<br>
File “site-packages\flask\app.py”, line 1950, in full_dispatch_request<br>
File “site-packages\flask\app.py”, line 1936, in dispatch_request<br>
File “pytorchVizTool\flaskr\ModelServer.py”, line 95, in GeneratePredsForFile<br>
File “pytorchVizTool\flaskr\ModelServer.py”, line 95, in<br>
File “pytorchVizTool\flaskr\FasterRCNN.py”, line 100, in predict<br>
File “pytorchVizTool\flaskr\FasterRCNN.py”, line 142, in get_bounding_box_prediction<br>
File “site-packages\torch\nn\modules\module.py”, line 550, in  <strong>call</strong><br>
File “site-packages\torchvision\models\detection\generalized_rcnn.py”, line 70, in forward<br>
File “site-packages\torch\nn\modules\module.py”, line 550, in  <strong>call</strong><br>
File “site-packages\torchvision\models\detection\rpn.py”, line 488, in forward<br>
File “site-packages\torchvision\models\detection\rpn.py”, line 410, in filter_proposals<br>
File “site-packages\torchvision\ops\boxes.py”, line 75, in batched_nms<br>
File “site-packages\torchvision\ops\boxes.py”, line 35, in nms<br>
File “site-packages\torch_ops.py”, line 61, in  <strong>getattr</strong><br>
RuntimeError: No such operator torchvision::nms</p>
<p>do you have any idea how i could fix this</p>