async def aiy_vision_task(callback): logger.info('starting aiy_vision_task') with InferenceEngine() as engine: while True: inference_state = engine.get_inference_state() camera_state = engine.get_camera_state() system_info = engine.get_system_info() firmware_info = engine.get_firmware_info() callback({ 'inference_state': { 'loaded_models': [str(x) for x in inference_state.loaded_models], 'processing_models': [str(x) for x in inference_state.processing_models], }, 'camera_state': { 'running': camera_state.running, 'width': camera_state.width, 'height': camera_state.height, }, 'system_info': { 'uptime_seconds': system_info.uptime_seconds, 'temperature_celsius': system_info.temperature_celsius, }, 'firmware_info': { 'version': firmware_info, } }) await asyncio.sleep(60)
def test_inference_state(self): with InferenceEngine() as engine: state = engine.get_inference_state() self.assertFalse(state.loaded_models) self.assertFalse(state.processing_models) model_name = engine.load_model(fd.model()) state = engine.get_inference_state() self.assertEqual(set(state.loaded_models), {model_name}) self.assertFalse(state.processing_models) engine.reset() state = engine.get_inference_state() self.assertFalse(state.loaded_models) self.assertFalse(state.processing_models) model_name = engine.load_model(fd.model()) with PiCamera(sensor_mode=4): engine.start_camera_inference(model_name) state = engine.get_inference_state() self.assertEqual(set(state.loaded_models), {model_name}) self.assertEqual(set(state.processing_models), {model_name}) engine.reset() state = engine.get_inference_state() self.assertFalse(state.loaded_models) self.assertFalse(state.processing_models)
def test_load_unload(self): with InferenceEngine() as engine: state = engine.get_inference_state() self.assertFalse(state.loaded_models) self.assertFalse(state.processing_models) model_name = engine.load_model(fd.model()) state = engine.get_inference_state() self.assertEqual(set(state.loaded_models), {model_name}) self.assertFalse(state.processing_models) with self.assertRaises(InferenceException): engine.unload_model('invalid_model_name') engine.unload_model(model_name) state = engine.get_inference_state() self.assertFalse(state.loaded_models) self.assertFalse(state.processing_models)
def test_camera_state(self): MODES = { 1: (1920, 1080), 2: (3280, 2464), 3: (3280, 2464), 4: (1640, 1232), 5: (1640, 922), 6: (1280, 720), 7: (640, 480) } with InferenceEngine() as engine: for mode, (width, height) in MODES.items(): state = engine.get_camera_state() self.assertFalse(state.running) with PiCamera(sensor_mode=mode): state = engine.get_camera_state() self.assertTrue(state.running) self.assertEqual(state.width, width) self.assertEqual(state.height, height) info = engine.get_system_info() state = engine.get_camera_state() self.assertFalse(state.running)
def test_system_info(self): with InferenceEngine() as engine: for _ in range(50): info = engine.get_system_info() self.assertTrue(hasattr(info, 'uptime_seconds')) self.assertTrue(hasattr(info, 'temperature_celsius'))
def test_firmware_info(self): with InferenceEngine() as engine: for _ in range(50): info = engine.get_firmware_info() self.assertTrue(hasattr(info, 'major')) self.assertTrue(hasattr(info, 'minor'))
def setUp(self): with InferenceEngine() as engine: engine.reset()
def _reset_inference_engine() -> None: logger.info('attempting to reset InferenceEngine') with InferenceEngine() as engine: engine.reset()