我一直在用TensorFlow训练一个量化的Mobilenet V2,但我不知道如何从它获得类索引。
我使用的是Tensorflow 1.12
下面是我的输入和输出的详细信息。
Input details [{'name': 'normalized_input_image_tensor', 'index': 260, 'shape': array([ 1, 300, 300, 3], dtype=int32), 'shape_signature': array([ 1, 300, 300, 3], dtype=int32), 'dtype': <class 'numpy.uint8'>, 'quantization': (0.0078125, 128), 'quantization_parameters': {'scales': array([0.0078125], dtype=float32), 'zero_points': array([128], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]
Output details [{'name': 'TFLite_Detection_PostProcess', 'index': 252, 'shape': array([ 1, 10, 4], dtype=int32), 'shape_signature': array([ 1, 10, 4], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}, {'name': 'TFLite_Detection_PostProcess:1', 'index': 253, 'shape': array([ 1, 10], dtype=int32), 'shape_signature': array([ 1, 10], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}, {'name': 'TFLite_Detection_PostProcess:2', 'index': 254, 'shape': array([ 1, 10], dtype=int32), 'shape_signature': array([ 1, 10], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}, {'name': 'TFLite_Detection_PostProcess:3', 'index': 255, 'shape': array([1], dtype=int32), 'shape_signature': array([1], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}}]我一直在尝试通过执行以下操作来获取类索引:
interpreter = tf.lite.Interpreter(model_path=PATH)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
interpreter.set_tensor(input_details[0]['index'], input_data)
interpreter.invoke()
classes = interpreter.get_tensor(output_details[1]['index'])[0]然而,类索引是不正确的。打印时,classes看起来像这样:[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]。我的数据集中有1个以上的类,所以这没有任何意义。
获取类索引的正确方法是什么?
发布于 2021-01-23 08:38:56
经过大量的实验,结果证明这不是一个量化问题。我们在创建.tflite时使用了错误的graph_def .pb文件,因此它预测了不存在的类。
发布于 2021-01-20 04:19:11
尝试使用:
classes = interpreter.get_tensor(output_details[0]['index'])https://stackoverflow.com/questions/65797318
复制相似问题