Open thesahibnanda opened 8 months ago
@thesahibnanda , thank you for the PR.
Per this comment https://github.com/keras-team/tf-keras/issues/766#issuecomment-2025846551 , the chosen approach is to add a new fill_mode
of "reflect"
to the existing keras.ops.image.PadImages
to make it very consistent with the existing API.
Can you modify this PR to move the logic to keras.ops.image.PadImages
? Thanks!
I Will Do It, Thanks For Guidance
Addressed Issue #766 (Feature Request)
Changes Made
ReflectionPadding1D
,ReflectionPadding2D
andReflectionPadding3D
to support Reflection Padding Layer in Tensorflow's Keras APIReflectionPadding
Functionality inBUILD
fileFiles Modified And Added
Usage
Example usage
model = tf.keras.Sequential([ ReflectionPadding1D(padding=1, input_shape=(10, 1)), tf.keras.layers.Conv1D(32, 3), tf.keras.layers.MaxPooling1D(2), tf.keras.layers.Flatten(), tf.keras.layers.Dense(10, activation='relu'), tf.keras.layers.Dense(1, activation='sigmoid') ])
Compile the model
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
Train the model
model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_val, y_val))
Example usage
model = tf.keras.Sequential([ ReflectionPadding3D(padding=((1, 1, 1), input_shape=(32, 32, 32, 3)), tf.keras.layers.Conv3D(64, (3, 3, 3), activation='relu'), tf.keras.layers.MaxPooling3D((2, 2, 2)), tf.keras.layers.Flatten(), tf.keras.layers.Dense(64, activation='relu'), tf.keras.layers.Dense(10, activation='softmax') ])
Compile the model
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
Train the model
model.fit(x_train, y_train, epochs=5, batch_size=32, validation_data=(x_val, y_val))