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

Find number of weeks in a month
breaking up a list entry in several lists at every /n Python 3
How can I get the default colors in GTK?
Ndb entry .put() not executed?
Tensorflow: NaNs propagating throughout network, even though using sparse_softmax etc
How to do a Python argparse mutually required argument group
scaling websocket game application server
Is there a way to find a character's Unicode code point in Python 2.7?
figtext datetime function matplotlib
environment variable in ubuntu
Cross-platform Python Executables
Extract subarray from collection of 2D coordinates?
tkinter populate treeview using threading pool
How to make a function determining the winner of Tic-Tac-Toe more concise
Django update model entry using form fails
ctypes using HRESULT(python)

Categories

HOME
sharepoint
swift
cakephp-3.x
crystal-reports
erlang
payment-gateway
winapi
ubuntu-16.04
d
ubuntu-12.04
is-empty
bro
simpy
eval
currency
wordpress-theming
spinnaker
tee
sign
attask
cython
plsqldeveloper
azure-servicebus-queues
jflex
superscript
apache-cloudstack
consumer
freebase
qtablewidget
transient
powershell-remoting
jquery-cycle2
google-guava-cache
rider
npm-publish
coreclr
declare
duktape
stdclass
html-agility-pack
resuming-training
matlab-cvst
facebook-chatbot
amazon-clouddrive
ideone
xmgrace
ogre3d
workflow-foundation-4.5
maintenance
slot
tcserver
etherpad
butterknife
laravel-query-builder
vici
objloader
nsfetchedresultscontrolle
hspec
alter
update-site
foxit
dojox.charting
multilingual-app-toolkit
remoteapp
elastix
except
test-class
lemoon
drf-nested-routers
plone-3.x
android-viewholder
geodjango
hyperthreading
selendroid
qbfc
apigee-baas
ytplayerview
pylearn
web-component-tester
git-checkout
guzzle6
uptodate
adodb
hg-git
pisa
cloudpebble
temp-tables
and-operator
node-imagemagick
docopt
author
io.js
phpdocx
circos
angulartics
fileconveyor
maven-ear-plugin
shared-objects
newsstand-kit
svn-hooks
sitemappath
jquery-ui-button
divx

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