Repository: mlcommons/inference
Issue: NameError: name 'interpreter_wrapper' is not defined
Root cause: Validation Gap

Hi,
What could be the reason for this error?

> # ./run_local.sh tflite --profile ssd-mobilenet-tf
> INFO:main:Namespace(accuracy=False, backend='tflite', cache=0, count=None, data_format=None, dataset='coco-300', dataset_list=None, dataset_path='/home/root/Ankita/data/coco', debug=False, find_peak_performance=False, inputs=['image_tensor:0'], max_batchsize=32, max_latency=None, mlperf_conf='../../mlperf.conf', model='/home/root/Ankita/model/resnet50_v1.tflite', model_name='ssd-mobilenet', output='/home/root/Ankita/inference/vision/classification_and_detection/output/tflite-cpu/resnet50', outputs=['num_detections:0', 'detection_boxes:0', 'detection_scores:0', 'detection_classes:0'], profile='ssd-mobilenet-tf', qps=None, samples_per_query=None, scenario='SingleStream', threads=4, time=None, user_conf='user.conf')
> INFO:coco:reduced image list, 4997 images not found
> INFO:coco:loaded 3 images, cache=0, took=9.0sec
> /home/root/Ankita/inference/vision/classification_and_detection/python/coco.py:115: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
>   self.label_list = np.array(self.label_list)
> Traceback (most recent call last):
>   File "python/main.py", line 558, in <module>
>     main()
>   File "python/main.py", line 436, in main
>     model = backend.load(args.model, inputs=args.inputs, outputs=args.outputs)
>   File "/home/root/Ankita/inference/vision/classification_and_detection/python/backend_tflite.py", line 32, in load
>     self.sess = interpreter_wrapper.Interpreter(model_path=model_path)
> NameError: name 'interpreter_wrapper' is not defined
> 

Thanks

what tensorflow version was this?
Seems to work for me with tf-2.5.


> what tensorflow version was this?
> Seems to work for me with tf-2.5.

I am working on riscv aarchitecture, tensorflow is not ported for it. We have tflite ported for riscv. Won't it work without tf?

Thanks

oh, you use the standanlone tflite package and not the one that comes with tf ?
I think I can fix that.

> oh, you use the standanlone tflite package and not the one that comes with tf ?
> I think I can fix that.

Yes, I am using standalone tflite.  Can you help me to fix it?

Thanks

> oh, you use the standanlone tflite package and not the one that comes with tf ?
> I think I can fix that.

@guschmue 
When can I expect the fix?  I am blocked because of this error.

Thanks 

@Ankita-020696 How do you build TFLite for RISC-V? On Arm platforms, we use [portable and customizable CK workflows](https://github.com/krai/ck-mlperf/tree/master/jnotebook/image-classification-tflite-loadgen). In theory, you could simply plug in your TFLite build into the workflow, but I've never worked with TFLite on RISC-V.

I think I know how to fix it - should get to it today or over the weekend


> I think I know how to fix it - should get to it today or over the weekend
@guschmue any update?

Thanks 

> @Ankita-020696 How do you build TFLite for RISC-V? On Arm platforms, we use [portable and customizable CK workflows](https://github.com/krai/ck-mlperf/tree/master/jnotebook/image-classification-tflite-loadgen). In theory, you could simply plug in your TFLite build into the workflow, but I've never worked with TFLite on RISC-V.

Hi @psyhtest @guschmue,
I am working with @Ankita-020696 

Following are the steps to build Tensorflow Lite using make.

1. Building RISC-V linux toolchain.

   1.Prerequisites: 
        Ubuntu 18.04
        Install packages: $ sudo apt-get install autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev

   2.toolchain is available at https://github.com/riscv/riscv-gnu-toolchain.git
	$ git clone https://github.com/riscv/riscv-gnu-toolchain.git --recursive
	$ cd riscv-gnu-toolchain && mkdir build
	$ ./configure --prefix='PATH-TO-build'
	$ make linux
	$ export PATH=$PATH:'PATH-TO-build'/bin

2. Building Tensorflow Lite

   1.Clone tensorflow & using make to build Tensorflow Lite for RISC-V
	$ git clone https://github.com/tensorflow/tensorflow.git
	$ cd tensorflow/tensorflow/lite/tools/make/
	$ ./download_dependencies.sh && ./build_riscv_lib.sh label_image
	$ cd gen/linux_riscv64
	
	Following are the executable and static file generated in gen/linux_riscv64: 
	bin/
	└── label_image
	lib/
	└── libtensorflow-lite.a
         
        Or To build benchmark_model :
	$ ./download_dependencies.sh && ./build_riscv_lib.sh
	$ cd gen/linux_riscv64   
	Following are the executables and static files generated in gen/linux_riscv64: 
        bin
       ├── benchmark_model
       ├── benchmark_model_performance_options
       └── minimal
        lib
       ├── benchmark-lib.a
       └── libtensorflow-lite.a

3. Testing on 'hifive unleashed' RISC-V development board:
	
   1. Copy label_image from host(x86_64) to development board.
   2. Download models on development board 
	$ wget https://storage.googleapis.com/download.tensorflow.org/models/tflite_11_05_08/mobilenet_v2_1.0_224.tgz
   3. Copy grace_hopper.bmp from host(x86_64) from location tensorflow/tensorflow/lite/examples/label_image/testdata to development board.
   4. Execution:
	$ ./label_image --tflite_model  mobilenet_v2_1.0_224.tflite -i grace_hopper.bmp --labels labels.txt
	
	



sorry for the delay, hope https://github.com/mlcommons/inference/pull/958 works

merged.