<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _encode_image(self, np_image):
 """Returns np_image encoded as jpeg or png."""

    if np_image.dtype != np.uint8:
      raise ValueError('Image should be uint8. Detected: %s.' % np_image.dtype)
    utils.assert_shape_match(np_image.shape, self._shape)
    return self._runner.run(ENCODE_FN[self._encoding_format], np_image)