0

How can I compile Python code with only the required parts or functions from a module, such as including Keras from TensorFlow but not the whole TensorFlow library? I have tried using PyInstaller and Nuitka, but they include the whole TensorFlow library, which is about 1GB, as well as NumPy and Matplotlib. My application is AINeuralNetwork-based, but after compiling it, the resulting application is a whole new application with a massive size. Is there any way to produce optimized binaries from Python that only include the necessary parts of a module? Here is an example-

# Importing only the required functions from a module
from tensorflow.keras.layers import Dense, Dropout

# Using the imported functions
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.2))

here only want the selected module to compile like Dense and Dropout not the whole Tensorflow Library. Things I tried to reduce the final output size-

  1. Virtual Env with only selected package
  2. Cx_freeze
  3. Nuitka
  4. Pyinstaller
  5. Numpy Vanilla libraries

But i want pure compiled version of my python program which is compiled in way that it automatically contain the required code from library not the whole library?

  • i don't even think this is possible in principle. certainly, anything that could accomplish this would rely on various heuristics. I've never heard of anything that attempts to. – juanpa.arrivillaga Apr 05 '23 at 09:30
  • does that means that no matter hard i try i can't get size less than gb when using tensorflow functions? even if its just linear regression or just print matrix? – korner253vn Apr 05 '23 at 12:11
  • Which parts of the tensorflow package can you safely remove without breaking it? – Alexander Apr 07 '23 at 09:54
  • I don't know why are you asking but my question is how can i decrease the size of python built program when using tensorflow ? cause a simple program which only add some matrix A and B the final size of program increases more than 1gb in size. – korner253vn May 01 '23 at 09:25

0 Answers0