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

GPU slows way down after a few loops
Google's verify_id_token function not working
ImportError: libgomp.so.1: cannot open shared object file: No such file or directory
Django Iterating through an object set with unique_together and no pk
Can i deploy a Django project using Apache that is not located in /var/www?
How to run a python script on images present in firebase?
dictionary variable formatting in Python's Mysqldb
How to see print output from generator before ending the cycle?
Python script- need help understanding this while loop [closed]
Reset weights of a pretrained incetion_v3 model in Tensorflow
Trying to connect to FTP site but getting wrong SSL version number error?
Bokeh plot conditional background color
module installation - Mock
Best Way to create a bounding box for object detection
Read csv from Amazon s3 using python2.7
Could someone explain this Python import error? Anaconda 3.5

Categories

HOME
visual-studio-2015
plsql
ssas-2012
system-verilog
antivirus
paramiko
jscript
laravel-4
algorithmic-trading
ext.net
avl-tree
eclipse-cdt
xamarin-studio
nixos
ctypes
symfony2-easyadmin
postmessage
ida
riak
opera-mini
apache-karaf
pycrypto
sonarqube-msbuild-runner
prediction
spring-ws
remove-method
npm-install
shopping-cart
croppic
frp
data-conversion
aurelia-binding
bitcoin-testnet
pygooglechart
piecewise
construct-2
backup-strategies
geopy
superpowered
mmdrawercontroller
image-compression
haskell-pipes
deepstream.io
intellilock
nsexception
spring-bean
email-parsing
estimation
data-integration
tiddlywiki
xmgrace
greenhills
chrome-remote-desktop
slot
crystal-reports-8.5
gce
vici
project-template
settimeout
coremidi
ebtables
spring-ioc
bacnet
qregexp
uwp-maps
twgl.js
sun-codemodel
acm
loose-typing
hateoas
affix
sem
ipojo
ubercart
pylearn
callstack
scrollspy
robocode
low-level
multipleselection
c++-actor-framework
symfony-2.6
proximity
odftoolkit
ibmsbt
iostream
xenocode
ksoap2
sqljdbc
ng-pattern
surveyor-gem
manage.py
prng
sunspot-rails
responsetext
objective-c-protocol
hobo
ou
django-nose
pivotal-crm
svn-hooks
dirty-data
project-lifecycle

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