Hello,
I’m trying to use EfficientNetB0 to create a model and save the model to my local disk. However, when saving it, it throws the error below, can anyone helps?
TypeError: Unable to serialize [2.0896919 2.1128857 2.1081853] to JSON. Unrecognized type <class 'tensorflow.python.framework.ops.EagerTensor'>.
Souce code of mine:
import os
import tensorflow as tf
from keras.applications import EfficientNetB0
os.environ["CUDA_VISIBLE_DEVICES"]="0" # single GPU
strategy = tf.distribute.MirroredStrategy(["GPU:0"])
print('\nnumber of devices using for training: {}'.format(strategy.num_replicas_in_sync))
print(tf.__version__)
with strategy.scope():
print('-- building model from scratch --')
img_dimension = (150, 280)
input_shape = (96, img_dimension[0], img_dimension[1], 3)
base_model = EfficientNetB0(weights='imagenet', input_shape=(input_shape[1:]), include_top=False,
drop_connect_rate=0.2)
base_model.save("D:/Program Files (x86)/CodeRepos/StartupProject/Training_Data/Output/demo")
Full error stacktrace
"D:\Program Files (x86)\CodeRepos\AutoUploader\venv\Scripts\python.exe" "D:/Program Files (x86)/CodeRepos/AutoUploader/main.py"
2022-10-19 21:31:07.149157: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-10-19 21:31:07.149769: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2022-10-19 21:31:09.584702: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2022-10-19 21:31:09.584908: W tensorflow/stream_executor/cuda/cuda_driver.cc:263] failed call to cuInit: UNKNOWN ERROR (303)
2022-10-19 21:31:09.591677: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-ETGPDN3
2022-10-19 21:31:09.591897: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-ETGPDN3
2022-10-19 21:31:09.592595: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING:tensorflow:Some requested devices in `tf.distribute.Strategy` are not visible to TensorFlow: /job:localhost/replica:0/task:0/device:GPU:0
number of devices using for training: 1
2.10.0
-- building model from scratch --
WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.
WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 81). These functions will not be directly callable after loading.
Traceback (most recent call last):
File "D:\Program Files (x86)\CodeRepos\AutoUploader\main.py", line 16, in <module>
base_model.save("D:/Program Files (x86)/CodeRepos/StartupProject/Training_Data/Output/demo")
File "D:\Program Files (x86)\CodeRepos\AutoUploader\venv\lib\site-packages\keras\utils\traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\Users\Whaley\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\Whaley\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
TypeError: Unable to serialize [2.0896919 2.1128857 2.1081853] to JSON. Unrecognized type <class 'tensorflow.python.framework.ops.EagerTensor'>.
Process finished with exit code 1