udibr / headlines

Automatically generate headlines to short articles

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed to find layer timedistributed_1 in model

timurmamedov opened this issue · comments

Hi I am currently trying to execute the following line of code...
weights = [np.copy(v) for v in f['timedistributed_1'].itervalues()] inside predict.ipynb , but keep getting the following error. I am not sure what might be causing it.

Perhaps an issue could be with the following code inside train.ipynb...

model.add(TimeDistributed(Dense(vocab_size, kernel_regularizer=regularizer, bias_regularizer=regularizer, name = 'timedistributed_1')))

but it seems ok to me

PS I am using TensorFlow if this helps

Error:

KeyError Traceback (most recent call last)
in ()
3 if 'layer_names' not in f.attrs and 'model_weights' in f:
4 f = f['model_weights']
----> 5 weights = [np.copy(v) for v in f['timedistributed_1'].itervalues()]

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/private/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/pip-wdzlRM-build/h5py/_objects.c:2840)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/private/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/pip-wdzlRM-build/h5py/_objects.c:2798)()

/usr/local/lib/python2.7/site-packages/h5py/_hl/group.pyc in getitem(self, name)
167 raise ValueError("Invalid HDF5 object reference")
168 else:
--> 169 oid = h5o.open(self.id, self._e(name), lapl=self._lapl)
170
171 otype = h5i.get_type(oid)

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/private/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/pip-wdzlRM-build/h5py/_objects.c:2840)()

h5py/_objects.pyx in h5py._objects.with_phil.wrapper (/private/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/pip-wdzlRM-build/h5py/_objects.c:2798)()

h5py/h5o.pyx in h5py.h5o.open (/private/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/pip-wdzlRM-build/h5py/h5o.c:3734)()

KeyError: "Unable to open object (Object 'timedistributed_1' doesn't exist)"

While running predict.py I am getting a similar issue wehn the model tries to load the trained weights.
Here is my snippet of the code (Though its not an error but I guess it can be checked once)

Loading /home/ubuntu/train.hdf5 to sequential_1 
embedding_1
lstm_1
dropout_1
lstm_2
dropout_2
lstm_3
dropout_3
simplecontext_1
timedistributed_1
failed to find layer timedistributed_1 in model
weights 944x40000 40000
stopping to load all other layers

@vibrantabhi19 I think it was an issue with version of Keras we are running. Try renaming all instances of string timedistributed_1 to time_distributed_1. Both in train and predict.

This fixed it for me, hope it helps!

Hence, I am closing the issue.