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

Getting an error: list assignment index out of range
Launching dev_appserver.py from windows powershell gives me “too few arguments” error
How do you split all of a certain character in Python [duplicate]
Issues with data types in pandas functions
Firebase Console but there is error tell “Error Generating Download URL”
Python Twitter Streaming Timeline
Interval intersection in pandas
Putting double quotes for an output string
How to query with raw SQL using Session or engine
getUser return EDAMSystemException errorCode=8
How to print the subject of a single email using uid
Avoiding Python globals in Google App/Cloud Engine
Python Google Voice get texts from [number]
Create a dictionary from values of a function, and using that for a graph
Attributes just disappear when I give a method as parameter
Send entries for FieldList of StringField from postman to flask

Categories

HOME
google-tag-manager
computer-vision
matplotlib
heap-memory
browserify
triggers
i2c
xcode8.3
vuex
lagom
wysiwyg
gatsby
mongodb-query
future
lenskit
zend-framework-mvc
attask
raphael
nsmenuitem
searchbar
switching
edge-detection
hana-studio
vertex-buffer
pygooglechart
crt
outsystems
nsurlconnection
phpspreadsheet
sidr
mms
autocompletetextview
rhel.net
sql-like
socketscan
tripwire
tango
ivona
mod-fcgid
encapsulation
prototypejs
w3-total-cache
gauss
gist
seamless-immutable
spring-data-hadoop
component-pascal
openh264
butterknife
search-box
barcode-printing
pspice
cjson
cron-task
git-annex
nofollow
gherkin
django-south
supportmapfragment
financial
xmp
getrusage
coldfusion-7
affix
zuora
app.xaml
python-winshell
mptcp
divide-by-zero
findcontrol
obfuscar
kallithea
omnifocus
em
emma
mfmailcomposeviewcontroll
voldemort
slick-2.0
bounds
convex-polygon
nimrod
html-form-post
htmltextwriter
android-4.0
attachevent
ubuntu-11.10
responsetext
associative
ruby-debug
pci-bus
usability-testing
callgrind
system-codedom-compiler
evb
standardized
data-execution-prevention

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