【发布时间】:2021-02-03 14:56:38
【问题描述】:
我需要调试它的行为,并且在第一步我得到了相当令人费解的结果。 当我在第一个 Conv2D 之后输入零张量作为输入时,我希望得到一个仅包含来自 Conv2D 偏差的值的张量(因为所有内核元素都乘以零),但是我得到了一个包含一些随机数据的张量,这里是代码sn-p:
def test_graph(path=PATH_DEFAULT):
interp = tf.lite.Interpreter(path)
interp.allocate_tensors()
input_details = interp.get_input_details()
in_idx = input_details[0]['index']
zeros = np.zeros(shape=(1, 256, 256, 3), dtype=np.float32)
interp.set_tensor(in_idx, zeros)
interp.invoke()
# index of output of first conv2d operator is 3 (see netron pic)
after_conv_2d = interp.get_tensor(3)
# shape of bias is just [count of output channels]
n, h, w, c = after_conv_2d.shape
# if we feed zeros as input, we can expect that the only values we get are the values of bias
# since all kernel elems in that case are multiplied by zeros
uniq_vals_cnt = len(np.unique(after_conv_2d))
assert uniq_vals_cnt <= c, f"There are {uniq_vals_cnt} in output, should be <= than {c}"
输出:
AssertionError: There are 287928 in output, should be <= than 24
谁能帮我解决我的误解?
【问题讨论】:
标签: tensorflow machine-learning tensorflow-lite