Load Model function not working #1920
Unanswered
jordannelson0
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
`import os
import autokeras as ak
import keras as k
def make_predictions(x):
classNames = ['KNN', 'Decision Tree', 'Random Forest', 'MLP', 'SVM',
'Naive Bayes']
make_predictions("Some text here")
`
There is my code.
Here is the error im getting:
/home/jordan/Documents/Brighton_University/PhD/New_Idea/venv/bin/python /home/jordan/Documents/Brighton_University/PhD/New_Idea/Weyland/background_processes/CNN.py
2024-05-17 16:58:33.183994: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable
TF_ENABLE_ONEDNN_OPTS=0
.2024-05-17 16:58:33.207463: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-05-17 16:58:33.595366: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Traceback (most recent call last):
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/venv/lib/python3.10/site-packages/keras/src/saving/serialization_lib.py", line 796, in _retrieve_class_or_fn
mod = importlib.import_module(module)
File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 992, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'keras.src.engine'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/Weyland/background_processes/CNN.py", line 40, in
make_predictions("Some text here")
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/Weyland/background_processes/CNN.py", line 16, in make_predictions
model = k.models.load_model(absolute_path, custom_objects=ak.CUSTOM_OBJECTS,
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/venv/lib/python3.10/site-packages/keras/src/saving/saving_api.py", line 176, in load_model
return saving_lib.load_model(
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/venv/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 152, in load_model
return _load_model_from_fileobj(
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/venv/lib/python3.10/site-packages/keras/src/saving/saving_lib.py", line 170, in _load_model_from_fileobj
model = deserialize_keras_object(
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/venv/lib/python3.10/site-packages/keras/src/saving/serialization_lib.py", line 694, in deserialize_keras_object
cls = _retrieve_class_or_fn(
File "/home/jordan/Documents/Brighton_University/PhD/New_Idea/venv/lib/python3.10/site-packages/keras/src/saving/serialization_lib.py", line 798, in _retrieve_class_or_fn
raise TypeError(
TypeError: Could not deserialize class 'Functional' because its parent module keras.src.engine.functional cannot be imported. Full object config: {'module': 'keras.src.engine.functional', 'class_name': 'Functional', 'config': {'name': 'model', 'trainable': True, 'layers': [{'module': 'keras.layers', 'class_name': 'InputLayer', 'config': {'batch_input_shape': [None, 333, 1], 'dtype': 'int64', 'sparse': False, 'ragged': False, 'name': 'input_1'}, 'registered_name': None, 'name': 'input_1', 'inbound_nodes': []}, {'module': 'autokeras.keras_layers', 'class_name': 'CastToFloat32', 'config': {'name': 'cast_to_float32', 'trainable': True, 'dtype': 'float32'}, 'registered_name': 'Custom>CastToFloat32', 'name': 'cast_to_float32', 'inbound_nodes': [[['input_1', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Conv1D', 'config': {'name': 'conv1d', 'trainable': True, 'dtype': 'float32', 'filters': 16, 'kernel_size': [7], 'strides': [1], 'padding': 'valid', 'data_format': 'channels_last', 'dilation_rate': [1], 'groups': 1, 'activation': 'relu', 'use_bias': True, 'kernel_initializer': {'module': 'keras.initializers', 'class_name': 'GlorotUniform', 'config': {'seed': None}, 'registered_name': None}, 'bias_initializer': {'module': 'keras.initializers', 'class_name': 'Zeros', 'config': {}, 'registered_name': None}, 'kernel_regularizer': None, 'bias_regularizer': None, 'activity_regularizer': None, 'kernel_constraint': None, 'bias_constraint': None}, 'registered_name': None, 'build_config': {'input_shape': [None, 333, 1]}, 'name': 'conv1d', 'inbound_nodes': [[['cast_to_float32', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Conv1D', 'config': {'name': 'conv1d_1', 'trainable': True, 'dtype': 'float32', 'filters': 64, 'kernel_size': [7], 'strides': [1], 'padding': 'valid', 'data_format': 'channels_last', 'dilation_rate': [1], 'groups': 1, 'activation': 'relu', 'use_bias': True, 'kernel_initializer': {'module': 'keras.initializers', 'class_name': 'GlorotUniform', 'config': {'seed': None}, 'registered_name': None}, 'bias_initializer': {'module': 'keras.initializers', 'class_name': 'Zeros', 'config': {}, 'registered_name': None}, 'kernel_regularizer': None, 'bias_regularizer': None, 'activity_regularizer': None, 'kernel_constraint': None, 'bias_constraint': None}, 'registered_name': None, 'build_config': {'input_shape': [None, 327, 16]}, 'name': 'conv1d_1', 'inbound_nodes': [[['conv1d', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Dropout', 'config': {'name': 'dropout', 'trainable': True, 'dtype': 'float32', 'rate': 0.25, 'noise_shape': None, 'seed': None}, 'registered_name': None, 'build_config': {'input_shape': [None, 321, 64]}, 'name': 'dropout', 'inbound_nodes': [[['conv1d_1', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Flatten', 'config': {'name': 'flatten', 'trainable': True, 'dtype': 'float32', 'data_format': 'channels_last'}, 'registered_name': None, 'name': 'flatten', 'inbound_nodes': [[['dropout', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Dropout', 'config': {'name': 'dropout_1', 'trainable': True, 'dtype': 'float32', 'rate': 0.5, 'noise_shape': None, 'seed': None}, 'registered_name': None, 'build_config': {'input_shape': [None, 20544]}, 'name': 'dropout_1', 'inbound_nodes': [[['flatten', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Dense', 'config': {'name': 'dense', 'trainable': True, 'dtype': 'float32', 'units': 6, 'activation': 'linear', 'use_bias': True, 'kernel_initializer': {'module': 'keras.initializers', 'class_name': 'GlorotUniform', 'config': {'seed': None}, 'registered_name': None}, 'bias_initializer': {'module': 'keras.initializers', 'class_name': 'Zeros', 'config': {}, 'registered_name': None}, 'kernel_regularizer': None, 'bias_regularizer': None, 'activity_regularizer': None, 'kernel_constraint': None, 'bias_constraint': None}, 'registered_name': None, 'build_config': {'input_shape': [None, 20544]}, 'name': 'dense', 'inbound_nodes': [[['dropout_1', 0, 0, {}]]]}, {'module': 'keras.layers', 'class_name': 'Activation', 'config': {'name': 'classification_head_1', 'trainable': True, 'dtype': 'float32', 'activation': 'sigmoid'}, 'registered_name': None, 'name': 'classification_head_1', 'inbound_nodes': [[['dense', 0, 0, {}]]]}], 'input_layers': [['input_1', 0, 0]], 'output_layers': [['classification_head_1', 0, 0]]}, 'registered_name': 'Functional', 'build_config': {'input_shape': [None, 333, 1]}, 'compile_config': {'optimizer': {'module': 'keras.optimizers', 'class_name': 'AdamW', 'config': {'name': 'AdamW', 'weight_decay': 0.01, 'clipnorm': None, 'global_clipnorm': None, 'clipvalue': None, 'use_ema': False, 'ema_momentum': 0.99, 'ema_overwrite_frequency': None, 'jit_compile': True, 'is_legacy_optimizer': False, 'learning_rate': {'module': 'autokeras.keras_layers', 'class_name': 'WarmUp', 'config': {'initial_learning_rate': 0.0001, 'decay_schedule_fn': {'module': 'keras.optimizers.schedules', 'class_name': 'PolynomialDecay', 'config': {'initial_learning_rate': 0.0001, 'decay_steps': 6000, 'end_learning_rate': 0.0, 'power': 1.0, 'cycle': False, 'name': None}, 'registered_name': None}, 'warmup_steps': 600, 'power': 1.0, 'name': None}, 'registered_name': 'Custom>WarmUp'}, 'beta_1': 0.9, 'beta_2': 0.999, 'epsilon': 1e-06, 'amsgrad': False}, 'registered_name': None}, 'loss': {'classification_head_1': {'module': 'keras.losses', 'class_name': 'BinaryCrossentropy', 'config': {'reduction': 'auto', 'name': 'binary_crossentropy', 'from_logits': False, 'label_smoothing': 0.0, 'axis': -1, 'fn': 'binary_crossentropy'}, 'registered_name': None}}, 'metrics': [[{'module': 'keras.metrics', 'class_name': 'MeanMetricWrapper', 'config': {'name': 'accuracy', 'dtype': 'float32', 'fn': {'module': 'builtins', 'class_name': 'function', 'config': 'categorical_accuracy', 'registered_name': 'function'}}, 'registered_name': None}]], 'loss_weights': None, 'weighted_metrics': None, 'run_eagerly': None, 'steps_per_execution': None, 'jit_compile': None}}
Current Working Directory: /home/jordan/Documents/Brighton_University/PhD/New_Idea/Weyland/background_processes
Absolute Path: /home/jordan/Documents/Brighton_University/PhD/New_Idea/Weyland/background_processes/../model_CNN.keras
Process finished with exit code 1
Beta Was this translation helpful? Give feedback.
All reactions