Faster_RCNN_for_Open_Images_Dataset_Keras icon indicating copy to clipboard operation
Faster_RCNN_for_Open_Images_Dataset_Keras copied to clipboard

Time_distributed_1 layer error

Open helenabdr opened this issue 3 years ago • 1 comments

Hi guys!

I get this error when I load the weights of a trained model with VGG19 as the base network. Does anyone have any ideas/suggestions about this? I would appreciate it very much.

Traceback (most recent call last): File "main.py", line 63, in <module> model_rpn, model_classifier = get_models(C, common_path, class_mapping) File "/home/helena/Documents/LAR_Celesc/robocelesc_backend/src/utils/model.py", line 76, in get_models model_classifier.load_weights(os.path.join(common_path, 'vgg19_3classes_test_with_no_param_var_classifier_weights.h5'), by_name=True) File "/home/helena/Documents/LAR_Celesc/robocelesc_backend/env/lib/python3.7/site-packages/keras/engine/saving.py", line 492, in load_wrapper return load_function(*args, **kwargs) File "/home/helena/Documents/LAR_Celesc/robocelesc_backend/env/lib/python3.7/site-packages/keras/engine/network.py", line 1227, in load_weights reshape=reshape) File "/home/helena/Documents/LAR_Celesc/robocelesc_backend/env/lib/python3.7/site-packages/keras/engine/saving.py", line 1309, in load_weights_from_hdf5_group_by_name ' element(s).') ValueError: Layer #40 (named "time_distributed_1") expects 0 weight(s), but the saved weights have 2 element(s).

The code is:

`input_shape_img = (None, None, 3)

img_input = Input(shape=input_shape_img)
roi_input = Input(shape=(C.num_rois, 4))
#feature_map_input = Input(shape=input_shape_features) 

shared_layers = nn.nn_base(img_input, trainable=False)

rpn_layers = nn.rpn(shared_layers, num_anchors)
classifier = nn.classifier(shared_layers, roi_input, C.num_rois, nb_classes=len(C.class_mapping), trainable=False)

# instantiate models
model_rpn = Model(img_input, rpn_layers)
model_classifier = Model([img_input, roi_input], classifier)

# load weights
model_rpn.load_weights(os.path.join(common_path, 'vgg19_3classes_test_with_no_param_var_rpn_weights.h5'), by_name=True)
model_classifier.load_weights(os.path.join(common_path, 'vgg19_3classes_test_with_no_param_var_classifier_weights.h5'), by_name=True)`

Regards, Helena.

helenabdr avatar May 03 '21 03:05 helenabdr

i think that after saving the config you change something in the code. delete everything u saved and then start over again

AlOo2002 avatar May 06 '21 12:05 AlOo2002