Пример #1
0
 def test_feed_non_supported_ndarray(self):
     blob = Blob()
     for dtype in [
             np.complex64, np.complex128, np.complex256, np.object, np.void
     ]:
         tensor = np.array([]).astype(dtype)
         with pytest.raises(TypeError):
             blob.feed('non_float_like_ndarray', tensor)
Пример #2
0
 def test_feed_float_like_ndarray(self):
     blob = Blob()
     for dtype in [
             np.int8, np.int16, np.int32, np.int64, np.uint8, np.uint16,
             np.uint32, np.uint64, np.float16, np.float32, np.float64,
             np.float128, np.bool
     ]:
         tensor = np.random.rand(1, 2, 3).astype(dtype)
         np.testing.assert_equal(tensor,
                                 blob.feed('float_like_ndarray', tensor))
Пример #3
0
    def capture(self):
        """The routine of video stream capturer capturation.

        Returns:
          `Blob`: The blob which contains "image" and "timestamp" tensor.

        Raises:
          RetryError: If the stream is live and disconnected temporarily.
          EndOfVideoError: If the stream ends.
        """
        if self._retry:
            try:
                logging.info('Start trying to open {}'.format(self._src))

                exec_timeout(self._retry_timeout, self._cap.open, self._src)
                self._retry = False

                logging.info('End trying to open {}'.format(self._src))
            except TimeoutError as e:
                logging.warn('Fail to open {} due to timeout: {}'.format(
                    self._src, e))
                self._raise_retry()

        success, image = self._cap.read()
        timestamp = np.array(now())

        if not success:
            if self._is_live_stream():
                self._retry = True
                self._raise_retry()
            else:
                raise EndOfVideoError('Video {} ends'.format(self._src))

        blob = Blob()
        blob.feed('image', image)
        blob.feed('timestamp', timestamp)

        return blob
Пример #4
0
 def test_feed_string_ndarray(self):
     blob = Blob()
     for dtype in [np.str, np.unicode]:
         tensor = np.array(['i love jagereye', 'hello']).astype(dtype)
         np.testing.assert_equal(tensor, blob.feed('string_ndarray',
                                                   tensor))
Пример #5
0
 def test_feed_non_ndarray(self):
     blob = Blob()
     for non_tensor in [100, [100], 'str']:
         with pytest.raises(TypeError):
             blob.feed('non__ndarray', non_tensor)
Пример #6
0
 def test_feed_with_non_string_name(self):
     blob = Blob()
     with pytest.raises(TypeError):
         blob.feed(100, np.array([]))
Пример #7
0
 def capture(self):
     blob = Blob()
     blob.feed('number', self._num)
     return blob