Hello everyone,
I’m trying to use transfer learning on my own dataset structured as:
datatset
healthy
unhealthy
First, I loaded these images off disk using image_dataset_from_directory.
Then, as good practice I split the dataset on train (80%), validation (10%) and test(10%) when developing the model.
batch_size = 32
img_height = 244
img_width = 244
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
image_path,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
class_names = train_ds.class_names
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
image_path,
validation_split=0.2,
subset="validation",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
val_batches = tf.data.experimental.cardinality(val_ds)
test_dataset = val_ds.take(val_batches // 5)
val_ds = val_ds.skip(val_batches // 5)
Then, when I’m going to train a simple model with Transfer Learning using the datasets we just prepared.
model = tf.keras.Sequential([
hub.KerasLayer('https://tfhub.dev/google/cropnet/feature_vector/cassava_disease_V1/1'),
tf.keras.layers.Dense(64, activation='relu'),
tf.keras.layers.Dense(2)
])
model.compile(
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
optimizer=tf.keras.optimizers.Adam(),
metrics=['accuracy']
)
log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
model.fit(train_ds, epochs=10, validation_data=val_ds, callbacks=[tensorboard_callback])
I’m getting the below error:
ValueError: Could not find matching function to call loaded from the SavedModel. Got:
Positional arguments (3 total):
* Tensor(“image:0”, shape=(None, 244, 244, 3), dtype=float32)
* False
* 0.99
Keyword arguments: {}Expected these arguments to match one of the following 4 option(s): Option 1: Positional arguments (3 total): * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image') * False * 0.99 Keyword arguments: {} Option 2: Positional arguments (3 total): * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image') * False * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum') Keyword arguments: {} Option 3: Positional arguments (3 total): * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image') * True * 0.99 Keyword arguments: {} Option 4: Positional arguments (3 total): * TensorSpec(shape=(None, 224, 224, 3), dtype=tf.float32, name='image') * True * TensorSpec(shape=(), dtype=tf.float32, name='batch_norm_momentum') Keyword arguments: {}