I have a tflite model, then I want to print weights of model, but it can't work. I search lots of information, still can't fix.
interpreter = tf.lite.Interpreter(model_path='/content/drive/MyDrive/non_RR/tflite_qaware_model.tflite')
interpreter.allocate_tensors()
tensor_details = interpreter.get_tensor_details()
for tensor in tensor_details:
print("Layer Name:", tensor['name'])
print("Shape:", tensor['shape'])
weights = interpreter.get_tensor(tensor['index'])
print("Weights:", weights)
Error messages:
ValueError Traceback (most recent call last)
<ipython-input-25-b3ca2c8bc8db> in <cell line: 6>()
7 print("Layer Name:", tensor['name'])
8 print("Shape:", tensor['shape'])
----> 9 weights = interpreter.get_tensor(tensor['index'])
10 print("Weights:", weights)
/usr/local/lib/python3.10/dist-packages/tensorflow/lite/python/interpreter.py in get_tensor(self, tensor_index, subgraph_index)
874 a numpy array.
875 """
--> 876 return self._interpreter.GetTensor(tensor_index, subgraph_index)
877
878 def tensor(self, tensor_index):
ValueError: Tensor data is null. Run allocate_tensors() first