my keras version is 2.2.4

from keras.applications import *

def model_InceptionResNetV2(img_dim, num_label):
    print('begin to get model')
    input_tensor = Input(shape=img_dim)
    base_model = InceptionResNetV2(include_top=False, input_shape=img_dim, weights='imagenet')
    x = input_tensor
    x = Lambda(preprocess_input, name='preprocessing')(x)
    x = base_model(x)
    x = GlobalAveragePooling2D()(x)
    x = Dropout(0.5)(x)
    print('num_label:', num_label)
    x = Dense(num_label, activation='softmax', name='softmax')(x)
    model = Model(input_tensor, x)

    return model

model.compile(optimizer=Adam(lr=1e-4), loss='binary_crossentropy', 
                      metrics = ['accuracy'])

        model.fit_generator(train_generator(), train_steps, epochs=epochs, verbose=1, 
                            callbacks= callbacks, validation_data=valid_generator(), 
        # save mode to JSON file and weights to HDF5
        model_json = model.to_yaml()
        model.load_weights(filepath='../model/aug_inception.fold_' + str(i) + attr_class + '.hdf5')
        #model_json = model.to_yaml()
        with open('../model/aug_inceptionresnetv2_model_' + str(i) + attr_class  + '.yaml', 'w') as json_file:

after I have trained mode, I want to load the mode as the following code:

load YAML and create model

yaml_file = open('../model/aug_inceptionresnetv2_model_1s.yaml', 'r')
loaded_model_yaml = yaml_file.read()
loaded_model = model_from_yaml(loaded_model_yaml)
# load weights into new model

and there is error as following:

~/.local/lib/python3.6/site-packages/keras/engine/base_layer.py in call(self, inputs, **kwargs)
455 # Actually call the layer,
456 # collecting output(s), mask(s), and shape(s).
--> 457 output = self.call(inputs, **kwargs)
458 output_mask = self.compute_mask(inputs, previous_mask)

~/.local/lib/python3.6/site-packages/keras/layers/core.py in call(self, inputs, mask)
685 if has_arg(self.function, 'mask'):
686 arguments['mask'] = mask
--> 687 return self.function(inputs, **arguments)
689 def compute_mask(self, inputs, mask=None):

~/.local/lib/python3.6/site-packages/keras/layers/core.py in wrapper(*args, **kwargs)
22 def wrapper(*args, **kwargs):
---> 23 if hasattr(keras_applications, 'get_submodules_from_kwargs'):
24 kwargs['backend'] = backend
25 kwargs['layers'] = layers

NameError: name 'keras_applications' is not defined

I don't know how to solve it, could you guys help me


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.