ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

How to run 'MobileNet v1 - int8 quant model' with ACL graph ??

Open gunjupark opened this issue 6 years ago • 0 comments

**Output of 'strings libarm_compute.so | grep arm_compute_version': ** arm_compute_version=v19.05 Build options: {'Werror': '1', 'debug': '0', 'asserts': '0', 'neon': '1', 'opencl': '1', 'embed_kernels': '1', 'os': 'android', 'arch': 'arm64-v8a'} Git hash=b'e9e0d15d17dce668f60645c4d4928cdb1a38f75e'

**Platform: ** Galaxy Note 10+ (CPU : Cortex®-A75 , GPU : ARM Mali ™-G76 MP12)

**Operating System: ** Android & Linux

Hello. ARM

I want to run ACL graph using Tensorflow's INT8 Quantized MobileNet V1 model (I think it was obtained by quantization aware training.)

But I could't get any information for get quantized weights. here's how to get MobileNet v2's float weight issue [https://github.com/ARM-software/ComputeLibrary/issues/748]

and how to get MobileNet V1's quantized weight in previous issue [https://github.com/ARM-software/ComputeLibrary/issues/748]

but both of aboves, I can't solve my problem.

I tried to get weights from *.tflite, so I implement the tflite extractor code.

here's code

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import argparse
import os

import numpy as np

from PIL import Image

from os import listdir
from os.path import isfile, join

import tensorflow as tf # TF2

if __name__ == '__main__':
  parser = argparse.ArgumentParser()
  parser.add_argument(
      '-m',
      '--model_file',
      default='/tmp/mobilenet_v1_1.0_224_quant.tflite',
      help='.tflite model to be executed')
  parser.add_argument(
      '-d',
      '--dump_path',
      default='tflite/mobilenet_v1/',
      help='.npy files to be saved')
  args = parser.parse_args()
  if not os.path.exists(args.dump_path):
    os.makedirs(args.dump_path)
  interpreter = tf.lite.Interpreter(model_path=args.model_file)
  interpreter.allocate_tensors()
  all_tensors= interpreter.get_tensor_details()
  for tensor in all_tensors:
    print(tensor)
    if 'weights' in tensor['name']:
      varname = tensor['name'][:-38];
      temp = interpreter.get_tensor(tensor['index'])
      tT = temp.transpose([0,3,2,1])
      res = np.ascontiguousarray(tT)
      print(varname)
      print(res.shape)
      print(tensor['quantization'])
      varname = tensor['name'][:-38]
      if os.path.sep in varname:
          varname = varname.replace(os.path.sep, '_')
      np.save(os.path.join(args.dump_path, varname), res)

and I got weights npy files using this code. image

Problem description: My problems are these.

In graph_mobilenet.cpp

  1. There is only two activation quantization factor. (input, middle, output) but in tensorflow lite model has factors of all activationmap quantization factor. image image

  2. no bias

  3. I can't see which method do you apply in mobilenet (post train ? , quantization aware train?)

Can you answer there questions? thank you

gunjupark avatar Jan 29 '20 01:01 gunjupark