--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[12], line 11 9 name = layer['name'] 10 shape = layer['shape'] ---> 11 weights = interpreter.get_tensor(layer['index']) 12 if op == 'CONV_2D': 13 x = tf.keras.layers.Conv2D( 14 filters=shape[-1], 15 kernel_size=shape[1:3], (...) 20 bias_initializer=tf.keras.initializers.Constant(weights[1]) 21 )(x) File ~\AppData\Roaming\Python\Python310\site-packages\tensorflow\lite\python\interpreter.py:852, in Interpreter.get_tensor(self, tensor_index, subgraph_index) 837 def get_tensor(self, tensor_index, subgraph_index=0): 838 """Gets the value of the output tensor (get a copy). 839 840 If you wish to avoid the copy, use `tensor()`. This function cannot be used (...) 850 a numpy array. 851 """ --> 852 return self._interpreter.GetTensor(tensor_index, subgraph_index) ValueError: Tensor data is null. Run allocate_tensors() first怎么解决
时间: 2023-09-17 14:14:32 浏览: 168
这个错误提示说明在获取张量数据之前需要先运行 `allocate_tensors()` 方法,以分配内存空间。可以在调用 `get_tensor()` 方法前先调用 `allocate_tensors()` 方法。例如:
```
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
tensor_index = output_details[0]['index']
tensor_data = interpreter.get_tensor(tensor_index)
```
阅读全文