You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NotImplementedError:
Layer ArcFace was created by passing
non-serializable argument values in __init__(),
and therefore the layer must override get_config() in
order to be serializable. Please implement get_config().
This is my code:
batch_size=32
train_datagen_names = keras.preprocessing.image.ImageDataGenerator(preprocessing_function=preprocess_input)
train_generator_names = train_datagen_names.flow_from_directory('/content/drive/MyDrive/train_dir',target_size=(224,224),color_mode='rgb',batch_size=32,class_mode='categorical',shuffle=True)
NO_CLASSES = len(train_generator_names.class_indices.values())
generate data
class train_Generator_xandy(object):
def init(self):
datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
NotImplementedError:
Layer ArcFace was created by passing
non-serializable argument values in
__init__()
,and therefore the layer must override
get_config()
inorder to be serializable. Please implement
get_config()
.Example:
class CustomLayer(keras.layers.Layer):
def init(self, arg1, arg2, **kwargs):
super().init(**kwargs)
self.arg1 = arg1
self.arg2 = arg2
This is my code:
batch_size=32
train_datagen_names = keras.preprocessing.image.ImageDataGenerator(preprocessing_function=preprocess_input)
train_generator_names = train_datagen_names.flow_from_directory('/content/drive/MyDrive/train_dir',target_size=(224,224),color_mode='rgb',batch_size=32,class_mode='categorical',shuffle=True)
NO_CLASSES = len(train_generator_names.class_indices.values())
generate data
class train_Generator_xandy(object):
def init(self):
datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
class val_Generator_xandy(object):
def init(self):
datagen = ImageDataGenerator(preprocessing_function=preprocess_input)
base_model = VGG16(include_top=False, weights='imagenet', input_shape=(224, 224, 3))
base_model.summary()
x = base_model.output
y = Input(shape=(NO_CLASSES, ))
x = BatchNormalization()(x)
x = Dropout(0.5)(x)
x = Flatten()(x)
x = Dense(128, kernel_initializer='he_normal',kernel_regularizer=keras.regularizers.l2(1e-4))(x)
#x = Dense(128, activation='relu')(x)
#predictions = Dense(num_classes, activation='softmax')(x)
predictions = ArcFace(NO_CLASSES,regularizer=keras.regularizers.l2(1e-4))([x, y])
model = Model(inputs=[base_model.input, y], outputs=predictions)
for layer in base_model.layers:
layer.trainable = False
model.summary()
opt = keras.optimizers.legacy.SGD(learning_rate=0.1, momentum=0.9, decay=5e-4, nesterov=True)
model.compile(loss='categorical_crossentropy',optimizer=opt,metrics=['accuracy'])
train_generator = train_Generator_xandy()
validation_generator = val_Generator_xandy()
model.fit(train_generator,batch_size = 1,verbose = 1,epochs = 20)
model.fit(
train_generator,
steps_per_epoch=batch_size,
epochs=10,
validation_data=validation_generator,
validation_steps=batch_size
)
creates a HDF5 file
model.save('transfer_learning_trained' + '_face_cnn_model.h5')
The text was updated successfully, but these errors were encountered: