Syed Shoaib Abbas
unread,Jul 25, 2023, 6:30:01 AMJul 25Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message as abuse
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Keras-users
import os
import uuid
from datetime import datetime
from tensorflow.keras.callbacks import ModelCheckpoint
# Generate a unique timestamp to be included in the checkpoint file name
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
unique_id = str(uuid.uuid4())[:8] # Use the first 8 characters of a UUID as an identifier
checkpoint_filepath = f"my_model_{timestamp}_{unique_id}.h5"
# Check if the checkpoint file exists
if os.path.exists(checkpoint_filepath):
# Delete the existing file
os.remove(checkpoint_filepath)
# Create ModelCheckpoint callback to save only the best model based on validation accuracy
model_checkpoint_callback = ModelCheckpoint(
filepath=checkpoint_filepath,
save_best_only=True,
monitor='val_accuracy',
mode='max',
verbose=1
)
# Update the fit() function to use the model_checkpoint_callback
history = avg_model.fit(
train,
epochs=50,
verbose=1,
callbacks=[model_checkpoint_callback],
validation_data=val,
validation_steps=16
)
here is i want to trained ensable learning model getting error.
ValueError: Unable to create dataset (name already exists)
i had tried many time but still error
the list of models that is ensambled
vgg16_model = tf.keras.models.load_model('/kaggle/input/modelsforensable/best_model.h5')
vgg19_model = tf.keras.models.load_model('/kaggle/input/modelsforensable/vgg19_best_model.h5')
inceptionv3_model = tf.keras.models.load_model('/kaggle/input/modelsforensable/inception_best_model.h5')
resnet101v2_model = tf.keras.models.load_model('/kaggle/input/modelsforensable/resnet101v2_best_model.h5')
model1= Model(inputs = vgg16_model.inputs, outputs = vgg16_model.outputs)
model2= Model(inputs = vgg19_model.inputs, outputs = vgg19_model.outputs)
model3= Model(inputs = inceptionv3_model.inputs , outputs = inceptionv3_model.outputs)
model4= Model(inputs = resnet101v2_model.inputs, outputs = resnet101v2_model.outputs)
models = [ model1, model2, model3, model4]
# average ensemble model
# import Average layer
from tensorflow.keras.layers import Average, Dense, Dropout
input = Input(shape=(256, 256, 3)) # input layer
# get output for each input model
model_outputs = [model(input) for model in models]
# take average of the outputs
x = Average()(model_outputs)
x = Dense(100, activation='relu')(x)
x = Dropout(0.3)(x)
output = Dense(38, activation='softmax', name='output')(x) # output layer
# create average ensembled model
avg_model = Model(inputs = input, outputs = output)