Problems bundling Tensorflow with Pyinstaller - No module named 'tensorflow.python.keras.engine.base_layer_v1'

Viewed 131

I've been having some problems with TensorFlow and Pyinstaller. My app works just fine on the terminal, but when I try to bundle it, it keeps crashing. The interface loads out, but when I try to predict some data with TensorFlow I get the error message: ModuleNotFoundError: No module named 'tensorflow.python.keras.engine.base_layer_v1'. Has someone had this problem before? Do you guys know how to solve it?

import tensorflow as tf
from tensorflow.keras.layers import Input, Dense, Lambda
from tensorflow.keras.models import Model
from tensorflow.keras.optimizers import Adam
import keras.engine #I have tried this, but it did not work

(...)

def model_creator(loss_function, opt):
    # Define inputs with predefined shape
    inputs = Input(shape=(5,)) # <<<The error occurred at this line>>>

    # Build network
    Layer1 = Dense(units=20, activation = 'sigmoid')
    Layer2 = Dense(units=20, activation = 'sigmoid')
    
    output1 = Layer1(inputs)
    #output2 = Layer2(output1)
    last_output = Layer2(output1)

    # Predict the parameters
    outputs = Dense(2)(last_output)

    # Construct model
    model = Model(
        inputs=inputs, 
        outputs=outputs
    )

    model.compile(
        loss = loss_function, 
        optimizer = opt
    )
    return model

(...)

1 Answers

Funny enough, for some reason, I could install every library with conda, but TensorFlow (I have used pip) 'cause some conflicts. After I have created a new env using just pip, the problem solved itself.

Related