-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Description
Issue
When running the current notebook, the following cell:
# custom loss function
def my_loss(y_true,y_pred): #A
loss = -tf.reduce_sum(tf.math.log(f(y_true,y_pred)))
return loss
# setup NN w/o hidden layer and with output node
model = Sequential()
model.add(Dense(1, activation='linear',
batch_input_shape=(None, 1)))
model.compile(loss=my_loss,optimizer="adam") # use custom lossException:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
[/tmp/ipython-input-175710984.py](https://colab.research.google.com/github/tensorchiefs/dl_book/blob/master/chapter_04/nb_ch04_03.ipynb#) in <cell line: 0>()
6 # setup NN w/o hidden layer and with output node
7 model = Sequential()
----> 8 model.add(Dense(1, activation='linear',
9 batch_input_shape=(None, 1)))
10 model.compile(loss=my_loss,optimizer="adam") # use custom loss
1 frames[/usr/local/lib/python3.12/dist-packages/keras/src/layers/core/dense.py](https://colab.research.google.com/github/tensorchiefs/dl_book/blob/master/chapter_04/nb_ch04_03.ipynb#) in __init__(self, units, activation, use_bias, kernel_initializer, bias_initializer, kernel_regularizer, bias_regularizer, activity_regularizer, kernel_constraint, bias_constraint, lora_rank, lora_alpha, **kwargs)
91 **kwargs,
92 ):
---> 93 super().__init__(activity_regularizer=activity_regularizer, **kwargs)
94 self.units = units
95 self.activation = activations.get(activation)
[/usr/local/lib/python3.12/dist-packages/keras/src/layers/layer.py](https://colab.research.google.com/github/tensorchiefs/dl_book/blob/master/chapter_04/nb_ch04_03.ipynb#) in __init__(self, activity_regularizer, trainable, dtype, autocast, name, **kwargs)
289 self._input_shape_arg = input_shape_arg
290 if kwargs:
--> 291 raise ValueError(
292 "Unrecognized keyword arguments "
293 f"passed to {self.__class__.__name__}: {kwargs}"
ValueError: Unrecognized keyword arguments passed to Dense: {'batch_input_shape': (None, 1)}
Context
-
This is due to recent changes in Keras / TensorFlow.
-
Denselayers no longer acceptbatch_input_shapedirectly; useinput_shape=(1,)instead. -
The rest of the notebook may need adjustments if other layers use similar deprecated arguments.
Suggested fix
Replace batch_input_shape=(None, 1) with input_shape=(1,).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels