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)
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))
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
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))
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)
def test_feed_with_non_string_name(self): blob = Blob() with pytest.raises(TypeError): blob.feed(100, np.array([]))
def capture(self): blob = Blob() blob.feed('number', self._num) return blob