python版本:2.7.5 张量流版本:1.2.0 bazel版本:
i want to use tensorflow bazel to quantize my trained model,the quantize code is follow:
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=/home/oup/zzl/zzl/AdversarialJPEG/JPEGFinalXu/Discriminative145000.pb \
--out_graph=/home/oup/zzl/zzl/AdversarialJPEG/JPEGFinalXu/quantized8_Discriminative145000.pb \
--outputs=Group_22/y_ \
--transforms='
strip_unused_nodes(type=float, shape="1,253,253,1")
fold_constants(ignore_errors=true)
fold_batch_norms
fold_old_batch_norms
quantize_nodes
quantize_weights(minimum_size=0)'
但是当我尝试获取训练有素的模型来测试其准确性时,我得到了错误:
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:04:00.0)
2018-07-27 14:01:15.643854: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:1) -> (device: 1, name: Tesla P100-PCIE-16GB, pci bus id: 0000:05:00.0)
2018-07-27 14:01:15.643863: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:2) -> (device: 2, name: Tesla P100-PCIE-16GB, pci bus id: 0000:8a:00.0)
Traceback (most recent call last):
File "testpb2.py", line 82, in <module>
_ = tf.import_graph_def(graph_def,name="")
File "/usr/lib/python2.7/site-packages/tensorflow/python/framework/importer.py", line 283, **in import_graph_def
raise ValueError('No op named %s in defined operations.' % node.op)
ValueError: No op named QuantizedAdd in defined operations.**
和导致错误的代码段:
with tf.Session(config=config) as sess:
#load the quantity model
with open(path+'quantized64_noDCT_retrained5000_Pruned_Discriminative145000.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
**_ = tf.import_graph_def(graph_def,name="")**
y_ = sess.graph.get_tensor_by_name('Group_22/y_:0')
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
init = tf.global_variables_initializer()
sess.run(init)
我不知道为什么我在量化代码中删除参数'quantize_nodes'正常工作,但是添加'quantize_nodes'会引发上述错误,我在Google上看到了该错误,但找不到任何解决方案,请给我一些有关该错误的建议,非常感谢!