Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

352
Views
TypeError: Exception encountered when calling layer "conv1d" (type Conv1D)

I am working on a project "News Classification". Where the model has to classify(multi-class classification problem) a given text into business, entertainment, politics, sport and tech.

I am using TensorFlow==2.7.0 on Google Colab. I had trained 7 different models. After, training and made prediction on it. When compared to all models, Conv1d performed the best. The best performing model saved model_2.save('saved_model/my_model').It has done well till here.

But, When I want to load the saved model using the code

loaded_model = tf.keras.models.load_model('saved_model/my_model') then, I am getting the below exception:

TypeError                                 Traceback (most recent call last)
<ipython-input-129-c92edaf0db7f> in <module>()
----> 1 load_model = tf.keras.models.load_model('saved_model/my_model')
      2 # load_model.preditct(val_sentences)

1 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/tensor_util.py in make_tensor_proto(values, dtype, shape, verify_shape, allow_broadcast)
    547       str_values = [compat.as_bytes(x) for x in proto_values]
    548     except TypeError:
--> 549       raise TypeError(f"Failed to convert elements of {values} to Tensor. "
    550                       "Consider casting elements to a supported type. See "
    551                       "https://www.tensorflow.org/api_docs/python/tf/dtypes "

TypeError: Exception encountered when calling layer "conv1d" (type Conv1D).

Failed to convert elements of tf.RaggedTensor(values=tf.RaggedTensor(values=Tensor("Placeholder:0", shape=(None, 128), dtype=float32), row_splits=Tensor("Placeholder_1:0", shape=(None,), dtype=int64)), row_splits=Tensor("conv1d/Conv1D/RaggedExpandDims/RaggedFromUniformRowLength/RowPartitionFromUniformRowLength/mul:0", shape=(None,), dtype=int64)) to Tensor. Consider casting elements to a supported type. See https://www.tensorflow.org/api_docs/python/tf/dtypes for supported TF dtypes.

Call arguments received:
  • inputs=tf.RaggedTensor(values=Tensor("Placeholder:0", shape=(None, 128), dtype=float32), row_splits=Tensor("Placeholder_1:0", shape=(None,), dtype=int64))

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It looks like you need to add .h5 on the file name. You need to add .h5 to the end of your file name. Instead of:

model_2.save('saved_model/my_model') try

model_2.save('saved_model/my_model.h5')
#Notice the .h5 -------------------^

You will also nee to change loaded_model = tf.keras.models.load_model('saved_model/my_model') to loaded_model = tf.keras.models.load_model('saved_model/my_model.h5')

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!