【问题标题】:Modify some values in the weight file (.h5) of VGG-16修改VGG-16的权重文件(.h5)中的一些值
【发布时间】:2020-11-04 06:43:37
【问题描述】:

我将 VGG 模型的每一层的权重和偏差值保存为 .h5 文件。我的文件来自:https://github.com/fchollet/deep-learning-models/releases/tag/v0.1

现在假设我想更改该文件中的一些值。在How to overwrite array inside h5 file using h5py 的帮助下,我正在尝试执行以下操作:

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()

即使在尝试将其他内容分配给该索引后,我也会得到相同的原始值。

我不确定如何更改/修改重量值并将其保存(在同一个文件中或可能在不同的文件中)。对此的任何帮助或建议将不胜感激。谢谢!

【问题讨论】:

    标签: python tensorflow conv-neural-network vgg-net


    【解决方案1】:

    试试这个。

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

    ndarray 对象需要以这种方式更新,而不是普通的数组列表。

    【讨论】:

      猜你喜欢
      • 2018-08-03
      • 2020-12-30
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2018-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多