C3W3_Assignment: UnimplementedError in train_model function

Hello, I am at the last assignment of the course and I receive an error that I don’t understand when I try to train the Siamese network using the train_model function.

The train_model function definition seems pretty straight forward, so I don’t understand where I could have gone wrong. I receive the following error message:

Epoch 1/2
Tensor("TripletLoss/diag_part:0", shape=(None,), dtype=float32)
Tensor("TripletLoss/diag_part:0", shape=(None,), dtype=float32)

---------------------------------------------------------------------------
UnimplementedError                        Traceback (most recent call last)
Cell In[26], line 9
      3 train_generator = train_dataset.shuffle(len(train_Q1),
      4                                         seed=7, 
      5                                         reshuffle_each_iteration=True).batch(batch_size=batch_size)
      6 val_generator = val_dataset.shuffle(len(val_Q1), 
      7                                    seed=7,
      8                                    reshuffle_each_iteration=True).batch(batch_size=batch_size)
----> 9 model = train_model(Siamese, TripletLoss,text_vectorization, 
     10                                             train_generator, 
     11                                             val_generator, 
     12                                             epochs=epochs,)

Cell In[25], line 29, in train_model(Siamese, TripletLoss, text_vectorizer, train_dataset, val_dataset, d_feature, lr, epochs)
     25 model.compile(loss=TripletLoss,
     26               optimizer = tf.keras.optimizers.Adam(learning_rate=lr)
     27         )
     28 # Train the model 
---> 29 model.fit(train_dataset,
     30           epochs = epochs,
     31           validation_data = val_dataset,
     32          )
     34 ### END CODE HERE ###
     36 return model
...
UnimplementedError: Graph execution error:
...
tensor = tf.cast(tensor, dtype=ref_input.dtype)
Node: 'SiameseModel/Cast'
2 root error(s) found.
  (0) UNIMPLEMENTED:  Cast string to float is not supported
	 [[{{node SiameseModel/Cast}}]]
  (1) CANCELLED:  Function was cancelled before it was started
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_26261]

make sure your input is a tensor and the data type is tf.string

1 Like