I’m trying to use EfficientNetB0 on Keras. The Keras model instantiates correctly, finds the training images and sets up the first epoch, but then the Python kernel dies and re-initializes.
It isn’t just EfficientNetB0 – other architectures that have worked fine now produce the same behavior. What’s different is that I’ve had to install keras-nightly in order to get the keras-efficientnets package. I reinstalled Keras 2.7.0 and Tensorflow 2.7.0 without uninstalling the other Keras versions, so what I have now is:
pip list | findstr "keras"
keras 2.7.0
keras-efficientnets 0.1.7
keras-nightly 2.9.0.dev2022011508
pip list | findstr "tensorflow"
tensorflow 2.7.0
tensorflow-estimator 2.7.0
tensorflow-gpu 2.7.0
tensorflow-io-gcs-filesystem 0.23.1
My training code, which has worked fine for various Keras model architectures, is below.
> def train(self, trainpath, validatepath, l_rate=.001, epochs=50, save_every_epoch=True, patience=50, batch_size=16):
> os.makedirs(trainpath, exist_ok=True)
> model = self.model
> nb_train_samples = sum(len(files) for _, _, files in os.walk(trainpath))
> nb_validation_samples = sum(len(files) for _, _, files in os.walk(validatepath))
> if save_every_epoch:
> mc = ModelCheckpoint(filepath=self.codepath+"saved-ResNet50-model-"+str(self.img_size)+"-{epoch:02d}-{accuracy:.2f}-{loss:.2f}.h5", \
> monitor='accuracy', verbose=1, save_best_only=False, mode='min')
> callbacks_list = [mc]
> else:
> es = EarlyStopping(monitor='accuracy', mode='min', verbose=1, patience=patience)
> mc = ModelCheckpoint(filepath=self.codepath+"ResNet50-model"+self.name+".h5", \
> monitor='accuracy', verbose=1, save_best_only=True)
> callbacks_list = [es, mc]
> model.compile(loss='binary_crossentropy',
> optimizer=Adam(lr=l_rate),
> metrics=['accuracy'])
> train_datagen = ImageDataGenerator(rescale=1. / 255,
> horizontal_flip=True, vertical_flip=True,
> brightness_range=[0.8,1.2])
> test_datagen = ImageDataGenerator(rescale=1. / 255)
> train_generator = train_datagen.flow_from_directory(
> trainpath,
> target_size=(self.img_size, self.img_size),
> class_mode='binary')
> validation_generator = test_datagen.flow_from_directory(
> validatepath,
> target_size=(self.img_size, self.img_size),
> batch_size=batch_size,
> class_mode='binary')
> print("Training "+self.name+" with tiles in "+trainpath)
> model.fit_generator(
> train_generator,
> epochs=epochs,
> callbacks=callbacks_list,
> validation_data=validation_generator)
> print(self.name+" trained successfully.\n")
> return