我想从TensorFlow python模型中转储每一层的输出
我从下面的代码获得的结果似乎不正确。我已经使用python脚本和CPP模型手动计算了卷积输出。两者都是一致的,我觉得TensorFlow输出存在问题
for idx in range(len(test_model.layers)):
if(idx!=-1):
print(test_model.layers[list(test_model.layers.keys())[i]])
pred = sess.run(test_model.layers[list(test_model.layers.keys())[idx]],
feed_dict={test_model.image: batch_data['image']})
print(pred.shape)
fo = open("../../layer_out/layer" + str(i) + "_out.txt",'w')
print(" Layer " + str(idx) + " Output " + str(pred.shape) +' ',list(test_model.layers.keys())[idx])
fo.write("Layer " + str(idx) + " Output " + str(pred.shape)+'\n' )
#print([i for i in np.ravel(pred)])
l = np.ravel(pred)
if(i==85):
print('Check////**************',max(l),np.where(l==max(l)))
print(label_dict[np.where(l==max(l))[0][0]])
for outval in (l):
fo.write(str(outval)+'\n')
print(str(outval))
#if(i==2):exit()
fo.close()