Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18789

SystemError: unknown opcode and model need compile errors

$
0
0

I am using Python 3.6 and Keras 2. I trained and saved a model in h5 format as follows:

# Encoder networkinputs_x = Input(shape=input_shape_x, name='encoder_input')inputs_x_dropout = Dropout(0.25)(inputs_x)inter_x1 = Dense(128, activation='tanh')(inputs_x_dropout)inter_x2 = Dense(intermediate_dim, activation='tanh')(inter_x1)z_mean = Dense(latent_dim, name='z_mean')(inter_x2)z_log_var = Dense(latent_dim, name='z_log_var')(inter_x2)z = Lambda(sampling, output_shape=(latent_dim,), name='z')([z_mean, z_log_var])encoder = Model(inputs_x, [z_mean, z_log_var, z], name='encoder')# Decoder network for reconstructionlatent_inputs = Input(shape=(latent_dim,), name='z_sampling')inter_y1 = Dense(intermediate_dim, activation='tanh')(latent_inputs)inter_y2 = Dense(128, activation='tanh')(inter_y1)outputs_reconstruction = Dense(original_dim)(inter_y2)decoder = Model(latent_inputs, outputs_reconstruction, name='decoder')# Separate network for prediction from latent spaceoutputs_prediction = Dense(Y.shape[1])(inter_y2)  # Adjust Y.shape[1] as per your datapredictor = Model(latent_inputs, outputs_prediction, name='predictor')from tensorflow.keras.metrics import AUC# Instantiate VAE model with two outputsoutputs_vae = [decoder(encoder(inputs_x)[2]), predictor(encoder(inputs_x)[2])]vae = Model(inputs_x, outputs_vae, name='vae_mlp')vae.compile(optimizer='adam', loss=['mean_squared_error', 'mean_squared_error'])# Train the modelhistory = vae.fit(X, [X, Y], epochs=5, batch_size=100, shuffle=True,validation_data=(XX,[XX, YY]), validation_split=0.0005)# Save models and plot training/validation lossencoder.save(" "+"BrmEnco Third.h5")decoder.save(" "+"BrmDeco Third.h5")predictor.save(" /"+"BrmPred Third.h5")vae.save("  "+"BrmAuto Third.h5")

However, when I tried to load the model I always get this message

2024-01-14 04:26:04.136452: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.WARNING:tensorflow:No training configuration found in the save file, so the model was *not* compiled. Compile it manually.Model: "predictor"Traceback (most recent call last):  File "c:/Users/mefgo/OneDrive - /P/CodeMatlab Simulation/Simulation.py", line 182, in <module>    encoder = load_model("C:/Users/mefgo/OneDrive - /P/CodeMatlab Simulation/"+"BrmEnco Third.h5")  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\saving\save.py", line 201, in load_model    compile)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\saving\hdf5_format.py", line 181, in load_model_from_hdf5    custom_objects=custom_objects)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\saving\model_config.py", line 52, in model_from_config    return deserialize(config, custom_objects=custom_objects)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\serialization.py", line 212, in deserialize    printable_module_name='layer')  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 678, in deserialize_keras_object    list(custom_objects.items())))  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\functional.py", line 663, in from_config    config, custom_objects)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\functional.py", line 1283, in reconstruct_from_config    process_node(layer, node_data)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\functional.py", line 1231, in process_node    output_tensors = layer(input_tensors, **kwargs)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 977, in __call__    input_list)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 1115, in _functional_construction_call    inputs, input_masks, args, kwargs)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 848, in _keras_tensor_symbolic_call    return self._infer_output_signature(inputs, args, kwargs, input_masks)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 888, in _infer_output_signature    outputs = call_fn(inputs, *args, **kwargs)  File "C:\Users\mefgo\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\core.py", line 903, in call    result = self.function(inputs, **kwargs)  File "c:/Users/mefgo/OneDrive - /PUF/CodeMatlab Simulation/Training.py", line 176, in sampling    z_mean, z_log_var = argsSystemError: unknown opcode

Viewing all articles
Browse latest Browse all 18789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>