AttributeError: type object 'TFLiteConverterV2' has no attribute 'from_frozen_gragh'
I was trying to convert my PyTorch model into TensorFlow lite for mobile. My model was pre-trained DenseNet 169 so I did this:-
import sys
import os
import torch
import torch.nn as nn
import torch.nn.functional as F
import onnx
from collections import OrderedDict
import tensorflow as tf

from torch.autograd import Variable
from onnx_tf.backend import prepare
dummy_input = Variable(torch.randn(32, 3, 224, 224))
torch.onnx.export(trained_model, dummy_input, &quot;mymodel.onnx&quot;)

model = onnx.load(&quot;mymodel.onnx&quot;)
tf_rep = prepare(model)

print('inputs:', tf_rep.inputs)

# Output nodes from the model
print('outputs:', tf_rep.outputs)

# All nodes in the model
print('tensor_dict:')
print(tf_rep.tensor_dict)

tf_rep.export_graph(&quot;mymodel.pb&quot;)
converter = tf.lite.TFLiteConverter.from_frozen_gragh(&quot;mymodel.pb/saved_model.pb&quot;, 
tf_rep.inputs, tf_rep.outputs) # **ERROR HERE**

tflite_model = converter.convert()
open(&quot;mymodel.tflite&quot;, &quot;wb&quot;).write(tflite_model)

HERE IS MY ERROR
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-37-0abbde392f91&gt; in &lt;module&gt;()
----&gt; 1 converter = tf.lite.TFLiteConverter.from_frozen_gragh(&quot;flowers.pb/saved_model.pb&quot;, tf_rep.inputs, tf_rep.outputs)
      
      2 tflite_model = converter.convert()
      3 open(&quot;flowers.tflite&quot;, &quot;wb&quot;).write(tflite_model)


AttributeError: type object 'TFLiteConverterV2' has no attribute 'from_frozen_gragh'

When I tried with compat.v1 I got the same error but instead of TFLiteConverterV2 I got TFLiteConverter
Thanks, in Advance.
EDIT
So I tried with compat.v1 and fixed the typo in 'from_frozen_gragh' and got this ugly error
---------------------------------------------------------------------------
DecodeError                               Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in from_frozen_graph(cls, graph_def_file, input_arrays, output_arrays, input_shapes)
   1804           graph_def = _graph_pb2.GraphDef()
-&gt; 1805           graph_def.ParseFromString(file_content)
   1806         except (_text_format.ParseError, DecodeError):

DecodeError: Error parsing message

During handling of the above exception, another exception occurred:

UnicodeDecodeError                        Traceback (most recent call last)
2 frames
&lt;ipython-input-32-46dac4006b0d&gt; in &lt;module&gt;()
----&gt; 1 tflitconverter = tf.compat.v1.lite.TFLiteConverter.from_frozen_graph(&quot;flowers.pb/saved_model.pb&quot;, tf_rep.inputs, tf_rep.outputs)
      2 e_model = converter.convert()
      3 open(&quot;flowers.tflite&quot;, &quot;wb&quot;).write(tflite_model)

/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in from_frozen_graph(cls, graph_def_file, input_arrays, output_arrays, input_shapes)
   1812                 file_content = six.ensure_binary(file_content, &quot;utf-8&quot;)
   1813               else:
-&gt; 1814                 file_content = six.ensure_text(file_content, &quot;utf-8&quot;)
   1815             graph_def = _graph_pb2.GraphDef()
   1816             _text_format.Merge(file_content, graph_def)

/usr/local/lib/python3.6/dist-packages/six.py in ensure_text(s, encoding, errors)
    933     &quot;&quot;&quot;
    934     if isinstance(s, binary_type):
--&gt; 935         return s.decode(encoding, errors)
    936     elif isinstance(s, text_type):
    937         return s

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb7 in position 3: invalid start byte

PLEASE HELP


it is &quot;from_frozen_graph&quot; not &quot;from_frozen_gragh&quot;
You need to use compat.v1 since from_frozen_graph is not available in TF 2.x

