我正在尝试加载我在 Google Colab 中训练过的模型,使用 Ubuntu 24.04、conda 24.5.0、NVIDIA-SMI 555.58.02、驱动程序版本 556.12、CUDA 12.5,我的所有驱动程序都已更新,但是当我……
我正在尝试加载一个我在 Google Colab 中训练过的模型,使用 Ubuntu 24.04、conda 24.5.0、NVIDIA-SMI 555.58.02、驱动程序版本 556.12、CUDA 12.5。我的所有驱动程序都已更新,但当我尝试运行以下代码时,它会卡在加载模型上。我已经尝试从 tensorflow.keras.models 导入模型函数并直接从 keras 加载,结果相同。我不得不将 python 从 3.12 降级到 3.9,否则 tensorflow 将无法工作,我也尝试加载在 colab 中加载的其他模型,结果类似。我可以选择将模型另存为 .keras,但这样做时,它会显示“加载模型时出错:SavedModel 文件不存在:model4.keras/{saved_model.pbtxt|saved_model.pb}”。我是否应该尝试特定的软件包版本组合以使此代码正常工作?欢迎任何指导。
import tensorflow as tf
from tensorflow import keras
print(tf.test.is_built_with_cuda())
print(tf.__version__)
try:
model1 = keras.models.load_model('model.h5')
print("Model loaded successfully")
except OSError as e:
print(f"Error loading model: {e}")
exit()
这是完整的输出:
2024-07-12 15:01:09.226398: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
True
2.4.1
2024-07-12 15:01:09.624582: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2024-07-12 15:01:09.625313: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2024-07-12 15:01:09.728371: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:01:09.728405: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: NVIDIA GeForce RTX 4070 computeCapability: 8.9
coreClock: 2.52GHz coreCount: 46 deviceMemorySize: 11.99GiB deviceMemoryBandwidth: 469.43GiB/s
2024-07-12 15:01:09.728420: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2024-07-12 15:01:09.729041: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10
2024-07-12 15:01:09.729073: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10
2024-07-12 15:01:09.729788: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2024-07-12 15:01:09.729909: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2024-07-12 15:01:09.730543: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2024-07-12 15:01:09.730889: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10
2024-07-12 15:01:09.732249: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7
2024-07-12 15:01:09.732301: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:01:09.732325: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:01:09.732338: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2024-07-12 15:01:09.732474: 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: SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-07-12 15:01:09.734681: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
2024-07-12 15:01:09.734728: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:01:09.734740: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: NVIDIA GeForce RTX 4070 computeCapability: 8.9
coreClock: 2.52GHz coreCount: 46 deviceMemorySize: 11.99GiB deviceMemoryBandwidth: 469.43GiB/s
2024-07-12 15:01:09.734745: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2024-07-12 15:01:09.734750: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.10
2024-07-12 15:01:09.734754: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.10
2024-07-12 15:01:09.734757: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2024-07-12 15:01:09.734760: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2024-07-12 15:01:09.734763: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10
2024-07-12 15:01:09.734780: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.10
2024-07-12 15:01:09.734796: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.7
2024-07-12 15:01:09.734809: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:01:09.734818: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:01:09.734821: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0
2024-07-12 15:01:09.734835: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2024-07-12 15:02:14.023639: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2024-07-12 15:02:14.023660: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267] 0
2024-07-12 15:02:14.023672: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1280] 0: N
2024-07-12 15:02:14.024163: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:02:14.024181: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1489] Could not identify NUMA node of platform GPU id 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2024-07-12 15:02:14.024211: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:02:14.024234: E tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:927] could not open file to read NUMA node: /sys/bus/pci/devices/0000:01:00.0/numa_node
Your kernel may have been built without NUMA support.
2024-07-12 15:02:14.024260: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1406] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10293 MB memory) -> physical GPU (device: 0, name: NVIDIA GeForce RTX 4070, pci bus id: 0000:01:00.0, compute capability: 8.9)
Traceback (most recent call last):
File "/home/abner/density/teste.py", line 8, in <module>
model1 = keras.models.load_model('model.h5')
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/saving/save.py", line 206, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 183, in load_model_from_hdf5
model = model_config_lib.model_from_config(model_config,
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/saving/model_config.py", line 64, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/layers/serialization.py", line 173, in deserialize
return generic_utils.deserialize_keras_object(
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 354, in deserialize_keras_object
return cls.from_config(
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/engine/functional.py", line 668, in from_config
input_tensors, output_tensors, created_layers = reconstruct_from_config(
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/engine/functional.py", line 1275, in reconstruct_from_config
process_layer(layer_data)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/engine/functional.py", line 1257, in process_layer
layer = deserialize_layer(layer_data, custom_objects=custom_objects)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/layers/serialization.py", line 173, in deserialize
return generic_utils.deserialize_keras_object(
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 360, in deserialize_keras_object
return cls.from_config(cls_config)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py", line 720, in from_config
return cls(**config)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/layers/pooling.py", line 862, in __init__
super(GlobalPooling2D, self).__init__(**kwargs)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/training/tracking/base.py", line 517, in _method_wrapper
result = method(self, *args, **kwargs)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/engine/base_layer.py", line 340, in __init__
generic_utils.validate_kwargs(kwargs, allowed_kwargs)
File "/home/abner/anaconda3/envs/density/lib/python3.9/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 808, in validate_kwargs
raise TypeError(error_message, kwarg)
TypeError: ('Keyword argument not understood:', 'keepdims')