1

I have a project based on ImageAI (the code is taken directly from the documentation), which uses tenserflow, keras and other dependencies, and it needs to be packed into an exe file.

The problem is that, so far, I haven't been able to do it, I've been using the pyinstaller library.But the problem I have with it is that I can not create a working exe file. Exe file closes in a fraction of a second.All hope is on you.

Now in more detail, here is the code itself:

from imageai.Detection import ObjectDetection
import easygui
import os


path = easygui.fileopenbox();
print(path);

exec_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(exec_path, "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()


list = detector.detectObjectsFromImage(
    input_image = os.path.join(exec_path, path),
    output_image_path= os.path.join(exec_path, "new_objects.jpg"),
    minimum_percentage_probability = 60)

I use the virtual environment "virtual env", in order to store all dependencies there, and nothing extra. At first I tried packing like this: pyinstaller detect.py, that is the most usual packing, but on this I got warnings that the right tenserflow files were not found, such as these:

166260 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.mixed_precision" not found!
166440 WARNING: Hidden import "tensorflow_core._api.v1.compat.v2.keras.callbacks" not found!
166615 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.estimator" not found!
166626 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.estimator.tpu" not found!
168300 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.estimator" not found!
168307 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.applications.nasnet" not found!
168839 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.activations" not found!
168854 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.preprocessing.text" not found!
169538 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.metrics" not found!
169711 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.applications.inception_v3" not found!
169815 WARNING: Hidden import "tensorflow_core._api.v1.compat.v1.keras.datasets.cifar10" not found!

And also some problems in the syntax of the library (although the code works correctly):

Traceback (most recent call last):
  File "<string>", line 21, in walk_packages
  File "c:\users\sleping\appdata\local\programs\python\python37-32\lib\site-packages\notebook\terminal\__init__.py", line 4, in <module>
    import terminado
  File "c:\users\sleping\appdata\local\programs\python\python37-32\lib\site-packages\terminado\__init__.py", line 7, in <module>
    from .websocket import TermSocket
  File "c:\users\sleping\appdata\local\programs\python\python37-32\lib\site-packages\terminado\websocket.py", line 18, in <module>
    import tornado.web
  File "c:\users\sleping\appdata\local\programs\python\python37-32\lib\site-packages\tornado\web.py", line 84, in <module>
    from tornado.concurrent import Future, future_set_result_unless_cancelled
  File "c:\users\sleping\appdata\local\programs\python\python37-32\lib\site-packages\tornado\concurrent.py", line 28, in <module>
    import asyncio
  File "c:\users\sleping\appdata\local\programs\python\python37-32\lib\site-packages\asyncio\__init__.py", line 21, in <module>
    from .base_events import *
  File "c:\users\sleping\appdata\local\programs\python\python37-32\lib\site-packages\asyncio\base_events.py", line 296
    future = tasks.async(future, loop=self)
                       ^
SyntaxError: invalid syntax

And everything in this spirit, after that I realized that it is necessary to connect the hidden imports and immediately connect the model (yolo.h5), which is actually what I did:

pyinstaller --paths ..\env\Lib\site-packages --add-data yolo.h5;. --hidden-import=h5py;. --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy detect.py

Unfortunately the result is still disappointing, although there is no message about the lack of tenserflow, and some other errors are also gone, in their place appeared new ones, such as:

241397 WARNING: Hidden import "pkg_resources.py2_warn" not found!
241417 WARNING: Hidden import "pkg_resources.markers" not found!

or:

255797 WARNING: lib not found: libopenblas.QVLO2T66WEPI7JZ63PS3HMOHFEY472BC.gfortran-win_amd64.dll dependency of C:\bitwise\pyinstaller_demo\env\Lib\site-packages\numpy\core\_multiarray_umath.cp37-win_amd64.pyd

And the problems with invalid syntax are the same, exactly the same as above.

To sum it up, I'm sorry the question got so big, I apologize for that. But I need this exe file badly, very badly. What solutions are available? Is it at all possible to pack such a project into an exe file? If yes, by what means is it possible? Or is it possible to solve the problem with pyinstaller?

Here are the dependencies I put in: tensorflow==2.4.0, keras==2.4.3, numpy==1.19.3, pillow==7.0.0, scipy==1.4.1, h5py==2.10.0, matplotlib==3.3.2, opencv-python, keras-resnet==0.2.0, imageai.In the project folder, I have the model "yolo.h5", to run machine learning

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Rick
  • 11
  • 2

1 Answers1

-1

1.first you need to save your tensorflow model weight i.e (model.pb)

  1. convert this into tensorflowlite (TF.lite) & you can use this in android phone

    load and save model -tensorflow

even you can refer this coursera course device-based-models-tensorflow

Akash Desai
  • 498
  • 5
  • 11
  • 1
    Thank you for your response. But I'm not sure if it will work for me, but I will try. – Rick Mar 16 '21 at 17:25