python


“KeyError: Can't open attribute (Can't locate attribute: 'nb_layers')” when trying to load weights with Keras


I am training a neural network in a very small set of data just to try and figure out how it works. Everything seems to be fine during training, the problem is when the program tries to save/load the weights.
Here's what seems to be the defective code (line 304, to 317):
f = h5py.File('models/vgg/vgg16_weights.h5')
for k in range(f.attrs['nb_layers']):
if k >= len(model_vgg.layers) - 1:
break
g = f['layer_{}'.format(k)]
weights = [g['param_{}'.format(p)] for p in range(g.attrs['nb_params'])]
layer = model_vgg.layers[k]
if layer.__class__.__name__ in ['Convolution1D', 'Convolution2D', 'Convolution3D', 'AtrousConvolution2D']:
weights[0] = np.transpose(weights[0], (2, 3, 1, 0))
layer.set_weights(weights)
f.close()
Here's the error:
Traceback (most recent call last):
File "train.py", line 305, in <module>
for k in range(f.attrs['nb_layers']):
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (D:\Buil
d\h5py\h5py-2.7.0\h5py\_objects.c:2853)
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (D:\Buil
d\h5py\h5py-2.7.0\h5py\_objects.c:2811)
File "C:\Users\Cliente\AppData\Local\Programs\Python\Python35\lib\site-package
s\h5py\_hl\attrs.py", line 58, in __getitem__
attr = h5a.open(self._id, self._e(name))
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (D:\Buil
d\h5py\h5py-2.7.0\h5py\_objects.c:2853)
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (D:\Buil
d\h5py\h5py-2.7.0\h5py\_objects.c:2811)
File "h5py\h5a.pyx", line 77, in h5py.h5a.open (D:\Build\h5py\h5py-2.7.0\h5py\
h5a.c:2350)
KeyError: "Can't open attribute (Can't locate attribute: 'nb_layers')"
What did I do wrong this time?
If you need more info please leave a comment.

Related Links

the difference between multiprocessing.sharedctypes.Value and multiprocessing.Value in python
TensorFlow placeholder dimension - what's the difference?
Python “scraping” maps/images
Python terminal output width
SQLAlchemy metadata column type with Postgresql interval hour to second
how to delete excel rows using python
Handling streaming data that gets saved in a file in python
Parsing XML column in SQL Alchemy results
Result wasn't printing, why is `print` ignored after `return`?
PySpark to MySQL Insert Error?
How to auto check dynamic data json and post it
IndexError: list index out of range - Odoo v8 to Odoo v10 community
Appending a Linklist Node to a queue
longest time lazy flappy bird can survive - consecutive gap between 2 arrays
Return outside of function gives an error but print works fine
Combine two tables only when 3 similar values using pandas python

Categories

HOME
numpy
plsql
udp
admin-on-rest
rotation
steam
transparent
codeeffects
safari
snap.svg
oclint
intellij-plugin
dryioc
data-synchronization
viber
x-frame-options
rapidjson
riak-ts
attask
ejbca
esql
extractor
pipelinedb
hanami
rhmap
owl-api
xilinx-ise
solidworks
pygooglechart
devforce
hibernate-cache
preg-grep
hawtio
ios-ui-automation
color-scheme
.net-assembly
mms
pmwiki
readfile
s3cmd
ddms
socketscan
onbackpressed
datalog
email-parsing
number-theory
quintus
paas
selenium-firefoxdriver
opencpu
addin-express
restivejs
alter
gitweb
foxit
linkageerror
nssplitview
mongoskin
image-editing
spatial-query
logcat
android-cursoradapter
python-winshell
programming-paradigms
bridge
and-operator
docopt
dalekjs
method-overriding
boost-test
osx-snow-leopard
argb
client-side-scripting
mailcore
zend-lucene
enumerators
icefaces-3
getstring
nintendo
scraperwiki
qtembedded
port-scanning
smooth
pureftpd
post-redirect-get
hibernate3-maven-plugin
external-assemblies
idictionary
windows-controls
virtualquery
interface-design

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App