Modify some values in the weight file (.h5) of VGG-16

空扰寡人 提交于 2020-07-23 06:15:10

问题


I have the weight and bias values for each layer of the VGG model saved as a .h5 file. I got the file from: https://github.com/fchollet/deep-learning-models/releases/tag/v0.1

Now let's say I want to change a few values in that file. With help from How to overwrite array inside h5 file using h5py, I am trying to do the same as follows:

import h5py
file_name = "vgg.h5"

f = h5py.File(file_name, 'r+')

# List all groups
print("Keys: %s" % f.keys())

# Get the data
data = (f['block2_conv1']['block2_conv1_W_1:0'])

print(data[0][0][0][0]) #prints some value, lets say X
data[0][0][0][0] = 0 #change it to zero
print(data[0][0][0][0]) #prints the same value X

f.close()

I get the same original value even after trying to assign something else to that index.

I am not sure how to change/modify the weight value and save it (in the same file or maybe a different one). Any help or suggestions on this will be highly appreciated. Thank you!


回答1:


Try this.

data[0,0,0,0]=0

ndarray objects need to update in this way rather than normal array-list.



来源:https://stackoverflow.com/questions/62903492/modify-some-values-in-the-weight-file-h5-of-vgg-16

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!