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

sudo/suid non-root nesting fails
Difference between a list & a stack in python?
Python continue Not Working Properly
list where multiple values have to be found and replaced with two new values
Tornado add delay between HTTP requests
Tensorflow: Convert Tensor to numpy array then pass into a feed_dict
How do I convert all python operations involving None to None values?
how to split the last element in the string
datetime.strptime unexpected behavior - locale issue
Repeating python code multiple times - is there a way of condensing it?
How to install scikit-learn for Python 3?
Passing several arguments for rendering template
Templating – Pass variable references in Python from a config file
Changing loop to organize and reduce XML output
How to do multiple operations in $filter?
django contenttype / genericforeignkey : why need content_type and object_id, if can be inferred from content_object

Categories

HOME
sql-server-2008
app-inventor
npm
thunderbird-addon
ruby-on-rails-3
bibtex
xtext
sequelize.js
jpanel
jboss-eap-7
informatica-powercenter
simple-injector
datagrip
internet-explorer-8
attask
cython
multiple-columns
jni
koa
plsqldeveloper
scalaz7
url.action
fop
hhvm
rworldmap
npm-install
fileinfo
bitcoin-testnet
dhtmlx-scheduler
lmdb
entity-system
idl
nsurlconnection
threshold
rhel.net
strstr
sql-like
equivalence
android-bitmap
pagefile
cdk
pycurl
castle-dynamicproxy
barcode-printing
spring-ioc
xib
linkageerror
nssplitview
squirrel
test-class
direct3d12
windows-vista
mysqldumpslow
mogrify
castle-windsor-3
xjc
ytplayerview
graphical-logo
debian-based
custom-url
ejabberd-saas
cpu-speed
ibmsbt
livechat
author
system.web
dache
httpcontext
exiv2
baucis
facebook-chat
nsmatrix
argb
resgen
attachevent
sequelpro
css-tables
die
applicationcontext
jquery-selectbox
path-manipulation
datamember
for-xml-path
ets
.app
virtualquery
hardware-infrastructure





Mobile Apps Dev
Database Users
javascript
java
csharp
php
android


MS Developer
developer works
python
ios
c
html
jquery


RDBMS discuss