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

How to extend instance with no class inheritance [duplicate]
How to check for inclusion of multisets?
why cv2.imwrite() changes the color of pics?
Optimize data conversion program to avoid memory error
Flask list of last used pages with sessions TypeError
python sqlite3.OperationalError: near “-”: syntax error
Using bokeh to select a data region within a Jupyter Notebook
Using asyncio nested_future() and gather() with nested loops
why does no picture show
SQLAlchemy: Error binding parameter 0 - probably unsupported type
Get path of file uploaded to Flask [duplicate]
How to load DICOM files in Python?
iPerf3 as a ssh.exec command using paramiko in Python
MemoryError when trying to append
Access the result of a previous calculation in custom function passed to apply()
multithreading: Second thread is waiting until first thread is finished

Categories

HOME
sas
security
ncurses
ipython
antivirus
bower
console
iis-7.5
jpanel
websphere-liberty
httpclient
desktop
vuex
cakephp-2.9
android-source
google-shopping
finite-group-theory
glpk
spring-cloud-config
off-canvas-menu
chocolatey
distance
deb
sensu
autolayout
servicemix
richfaces
spring-ws
multiplayer
rworldmap
delete-file
qsub
myob
badge
compare-and-swap
aurelia-binding
blackboard
edb
receipt
rider
.net-assembly
autocompletetextview
forecasting
socketpair
initializer
nashorn
mediawiki-extensions
pdftk
dojox.mobile
finite-element-analysis
jdbi
appstore-approval
broadcast
workflow-foundation-4.5
chrome-remote-desktop
heroku-postgres
photography
emoticons
sqlexception
master
iostat
glkit
dbscan
selecteditem
group-concat
yoothemes
galaxy
lmfit
uialertview
programming-paradigms
integral
on-duplicate-key
low-level
temp-tables
gyroscope-framework
em
sthttprequest
facebook-wall
boost-test
kraken.js
slick-2.0
mimosa
jquery-tabs
logentries
java.util.date
zend-lucene
htmltextwriter
fieldset
vt100
snapjs
sametime
blockingqueue
javascriptserializer
plone-funnelweb
xmlslurper
selectonemenu
path-manipulation
querystringparameter
shared-objects
charts4j
msbuildextensionpack
noir
zend-form-element
email-spec
carbide
front-controller
openvg
hmacsha1
project-lifecycle
visual-studio-dbpro

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