Open caginozkaya opened 1 year ago
Fixed. I think the problem is related to tf version.I have also added tf.cast. Here is the code:
smooth = 1.
def dice_coef(y_true, y_pred): y_true_f = tf.compat.v1.layers.flatten(y_true) y_pred_f = tf.compat.v1.layers.flatten(y_pred) intersection = tf.compat.v1.reduce_sum(y_true_f y_pred_f) return (2. intersection + smooth) / (tf.reduce_sum(y_true_f) + tf.reduce_sum(y_pred_f) + smooth)
def dice_coef_loss(y_true, y_pred): y_true = tf.compat.v1.cast(y_true, tf.float32) pred = tf.compat.v1.cast(y_true, tf.float32) return 1.0 - dice_coef(y_true, y_pred)
I am getting TypeError when I run the dice_coef_loss in model.fit:
TypeError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_15776/2786157346.py in
----> 1 results = model.fit(X_train, Y_train, validation_split=0.1, batch_size=4, callbacks = model_checkpoint_callback, epochs=100)
C:\ProgramData\Anaconda3\envs\env1\lib\site-packages\keras\utils\traceback_utils.py in error_handler(*args, **kwargs) 65 except Exception as e: # pylint: disable=broad-except 66 filtered_tb = _process_traceback_frames(e.traceback) ---> 67 raise e.with_traceback(filtered_tb) from None 68 finally: 69 del filtered_tb
C:\ProgramData\Anaconda3\envs\env1\lib\site-packages\tensorflow\python\framework\func_graph.py in autograph_handler(*args, **kwargs) 1145 except Exception as e: # pylint:disable=broad-except 1146 if hasattr(e, "ag_error_metadata"): -> 1147 raise e.ag_error_metadata.to_exception(e) 1148 else: 1149 raise
TypeError: in user code: