google-coral / tflite

Examples using TensorFlow Lite API to run inference on Coral devices
https://coral.withgoogle.com
Apache License 2.0
181 stars 67 forks source link

Cannot set input tensor #42

Closed GrantPerkins closed 3 years ago

GrantPerkins commented 3 years ago

RuntimeError: There is at least 1 reference to internal data in the interpreter in the form of a numpy array or slice. Be sure to only hold the function returned from tensor() if you are using raw data access.

This occurs when running:

    def input_tensor(self):
        """Returns input tensor view as numpy array of shape (height, width, 3)."""
        tensor_index = self.interpreter.get_input_details()[0]['index']
        return self.interpreter.tensor(tensor_index)()[0]

    def set_input(self, frame):
        """Copies a resized and properly zero-padded image to the input tensor.
        Args:
          size: original image size as (width, height) tuple.
          resize: a function that takes a (width, height) tuple, and returns an RGB
            image resized to those dimensions.
        Returns:
          Actual resize ratio, which should be passed to `get_output` function.
        """
        width, height = self.input_size()
        w, h = frame.size
        scale = min(width / w, height / h)
        w, h = int(w * scale), int(h * scale)
        tensor = self.input_tensor()
        tensor.fill(0)  # padding
        _, _, channel = tensor.shape
        tensor[:h, :w] = np.reshape(frame.resize((w, h), Image.ANTIALIAS), (h, w, 3))
        return scale, scale
Namburger commented 3 years ago

This doesn't tell me a lot, what input are you feeding into the function and how are you calling it> also, what platform?

manoj7410 commented 3 years ago

Closing this due to lack of activity. Feel free to reopen this thread if the issue still persists.