Hello everyone.
I’m trying to use EfficientNet B0 as a transfer learning approach so I want the weights of pre trained network. Now the problem is I want to use grayscale images (single channel) and a 28x28 size for the images. I have tried different techniques like the below : #Transfer Learning for a 28x28x1
import tensorflow as tf
from tensorflow.keras.applications import EfficientNetB0
from tensorflow.keras.layers import GlobalAveragePooling2D, Dense, Resizing
from tensorflow.keras.models import Model
NUM_CLASSES = 6
Load the pre-trained EfficientNet B0 model
base_model = EfficientNetB0(include_top=False, weights=‘imagenet’, input_shape=None)
Add new layers for your classification task
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(6, activation=‘softmax’)(x)
Create the new model
inputs = tf.keras.layers.Input(shape=(28, 28, 1))
y = Resizing(224, 224)(inputs)
y = tf.keras.applications.efficientnet.preprocess_input(y)
y = base_model(y)
y = GlobalAveragePooling2D()(y)
outputs = Dense(6, activation=‘softmax’)(y)
model = tf.keras.models.Model(inputs, outputs)
Freeze the weights of the pre-trained layers
for layer in base_model.layers:
layer.trainable = False
But this gave me a warning : WARNING:tensorflow:Model was constructed with shape (None, None, None, 3) for input KerasTensor(type_spec=TensorSpec(shape=(None, None, None, 3), dtype=tf.float32, name=‘input_10’), name=‘input_10’, description=“created by layer ‘input_10’”), but it was called on an input with incompatible shape (None, 224, 224, 1).
I tried moving around with the above snippet but all in vain.
Note my goal is to later go for hardware so I need only grayscale and 28x28 to work how can I make it work for that???