我有一个有很多 conv2d 层的模型。我将模型转换为 Tflite 模型。转换后我得到单个 conv2d 的权重。重量的形状看起来像这样
# code
w2 = get_variable(interpreter, 1)
print(w2.shape)
# output
(16, 3, 3, 3)
w2 是我从 tflite 模型获得的 conv2d 层的权重。
# looking at weights
tf.constant(w2)
# out
<tf.Tensor: shape=(16, 3, 3, 3), dtype=float32, numpy=
array([[[[-0.09935276, 0.02673087, 0.01329462],
[-0.15000243, 0.12058315, 0.06234892],
[-0.04185663, -0.11198951, -0.02449715]],
[[-0.01043741, 0.00516671, -0.04251045],
[ 0.09123346, -0.18056516, -0.15848799],
[ 0.13060766, -0.07997198, -0.01930575]],
[[-0.03572255, -0.01315425, 0.08955526],
[ 0.16559589, 0.03411882, 0.0018566 ],
[-0.14274003, 0.1362513 , 0.02790332]]],
[[[-0.18470907, -0.08563003, -0.1520263 ],
[-0.04288448, -0.18342438, -0.15801121],
[-0.03374813, 0.06371641, 0.03502055]],
现在是我使用命令 model.weights 从模型文件中获得的权重。
# code
model_layer = model.get_layer(index = 1)
model_layer.weights[0]
# out
<tf.Variable 'conv2d/kernel:0' shape=(3, 3, 3, 16) dtype=float32, numpy=
array([[[[-0.09935276, -0.18470907, -0.16035978, -0.00957598,
0.12404141, 0.09072036, 0.08940545, 0.16788253,
-0.09028493, -0.07161955, 0.05057701, 0.00413197,
0.12936822, 0.13274643, -0.11566465, 0.06050111],
[ 0.02673087, -0.08563003, 0.15529695, -0.16517243,
0.09419081, 0.03450985, 0.05399269, 0.06663677,
-0.1096884 , 0.11150008, -0.14434202, 0.08073789,
-0.00857992, 0.17634535, -0.1686475 , -0.02407928],
[ 0.01329462, -0.1520263 , -0.16246322, -0.06716946,
0.18214822, -0.13206367, -0.05873053, 0.13359356,
0.13813934, -0.05382906, 0.1032899 , 0.03165779,
我想要的是转换权重 w2 以便将其分配给我的图层的正确方法。
慕桂英4014372
相关分类