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

Scrapy - Importing Excel .csv as start_url
Make a simple audio player with a playback control with gstreamer1.0 and gtk3
error in writing a text file in python [closed]
ipython using 2.6 version instead of 2.7
Django: How to override authenticate() method?
Execute python script with a variable from linux shell
Output loop result into a list
Pyinstaller will create an executable with --onefile, but not without it
PyMongo update multiple records with multiple data
How to automatically input ssh private key passphrase with pexpect
Extract only the portion of a string between two regex patterns
Filtering dictionary keys by a function of their associated values
webrtc without a browser
Simple python IF statement not working?
Python: aliased to python3
replacing certain expressions in file but only one time

Categories

HOME
reverse-engineering
checkbox
wmic
uibutton
reportportal
hana
adsense
xtext
tumblr
data-science-experience
internet-explorer-11
goutte
shipping
pca
jboss-eap-7
wordpress-theming
jboss7.x
cortex-a
dryioc
arm-template
jpeg2000
google-api-java-client
tweets
kitematic
tampermonkey
pipelinedb
bus-error
maximo
version-numbering
spring-data-neo4j
multichoiceitems
red-black-tree
rowcount
android-vpn-service
construct-2
polymorphism
pljson
fabric-digits
qtablewidget
von-neumann
viewstate
npm-publish
inkscape
ntfs-mft
ical-dotnet
intersystems-ensemble
pytest-django
worker
rapidweaver
recycle-bin
taskmanager
defold
jags
slot
google-maps-ios
volume
addin-express
lotus
efxclipse
sql-server-administration
update-site
dts
gradle-eclipse
emokit
console-redirect
axes
handlebars.java
void
function-fitting
insert-into
evo
lmfit
p-np
mptcp
ctrlp
chaining
inputaccessoryview
temp-tables
kendo-mvvm
ultrawingrid
ibmsbt
libssh2
eclipse-classpath
xenocode
sanitization
confusion-matrix
vertical-rhythm
trimming
vmware-server
sharpmap
xslkey
awesomeprint
domain-calculus
crocodoc
git-filter-branch
datarepeater
law-of-demeter
hinstance
windows-live-id
junit3
post-redirect-get
asp.net-mvc-controller
data-entry
associativity





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