Arsey/keras-transfer-learning-for-oxford102

me again. Keyerror. "Unable to open object (Object 'fc1' doesn't exist)"

TriLoo opened this issue · 4 comments

File "train.py", line 39, in <module> fine_tuning.tune() File "/home/slz/Desktop/myvgg/fine_tuning.py", line 10, in tune model = util.load_model(nb_class=len(config.classes), weights_path=config.top_model_weights_path) File "/home/slz/Desktop/myvgg/util.py", line 130, in load_model output=base_model.output) File "/home/slz/Desktop/myvgg/util.py", line 89, in get_top_model_for_VGG16 weights_1 = get_layer_weights(weights_file, 'fc1') File "/home/slz/Desktop/myvgg/util.py", line 67, in get_layer_weights g = weights_file[layer_name] File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2841) File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2799) File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/group.py", line 166, in __getitem__ oid = h5o.open(self.id, self._e(name), lapl=self._lapl) File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2841) File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/tmp/pip_build_root/h5py/h5py/_objects.c:2799) File "h5py/h5o.pyx", line 190, in h5py.h5o.open (/tmp/pip_build_root/h5py/h5py/h5o.c:3727) KeyError: "Unable to open object (Object 'fc1' doesn't exist)"

Arsey commented

please create a trained dir in the project folder and run training again

Yes, this step I have fixed, meanwhile, I also create a plots dir in the folder ...
I think this info told that the name of layer may be wrong , i.e. no 'fc1' layer.
besides, what's the purpose of get_layer_weights(weights_file, 'fc1')
thankyou.

the reason may be that in bottlenecks.py:
model = VGG16(weights='imagenet', include_top=False)
So there is no top Dense layers as shown in vgg16.py:
if include_top: # Classification block x = Flatten(name='flatten')(x) x = Dense(4096, activation='relu', name='fc1')(x) x = Dense(4096, activation='relu', name='fc2')(x) x = Dense(1000, activation='softmax', name='predictions')(x)
leading to the result that when loading weights in utils.py:
weights_1 = get_layer_weights(weights_file, 'fc1')
in fact, there is no 'fc1' if we don't set include_top = true when calling vgg16 model ...

Arsey commented

I've refactored code, now the issue should be fixed.