def classify(self, batch: FrameBatch) -> List[Prediction]: frames = batch.frames_as_numpy_array() (pred_classes, pred_scores, pred_boxes) = self._get_predictions(frames) return Prediction.predictions_from_batch_and_lists(batch, pred_classes, pred_scores, boxes=pred_boxes)
def test_frames_as_numpy_array_should_frames_as_numpy_array(self): batch = FrameBatch(frames=[ Frame(1, np.ones((1, 1)), None), Frame(1, np.ones((1, 1)), None) ], info=None) expected = list(np.ones((2, 1, 1))) actual = list(batch.frames_as_numpy_array()) self.assertEqual(expected, actual)
def classify(self, batch: FrameBatch) -> List[Prediction]: """ Takes as input a batch of frames and returns the predictions by applying the classification model. Arguments: batch (FrameBatch): Input batch of frames on which prediction needs to be made Returns: List[Prediction]: The predictions made by the classifier """ pred = self.model.predict(batch.frames_as_numpy_array()) return [self.labels()[np.argmax(l)] for l in pred]
def test_frame_filtering_for_depth_estimation(self): """ Unit test method to test frame filtering functionality. it loops over frames and sends them over to frame filtering object's apply_filter method. Finally it verifies that depth mask is applied to the frames except every fifth one. """ # create two frames from kitti car dataset frame_1 = Frame( 1, self._load_image( os.path.join(self.base_path, 'data', 'kitti_car_1.png')), None) frame_2 = Frame( 1, self._load_image( os.path.join(self.base_path, 'data', 'kitti_car_2.png')), None) # create a batch of 2 frames frame_batch = FrameBatch([frame_1, frame_2], None) frames = frame_batch.frames_as_numpy_array() # initialize the frame filtering class object frame_filter = FrameFilter() # create a random depth mask array depth_mask = np.random.rand(frames[0].shape[0], frames[0].shape[1], frames[0].shape[2]) # iterate over frames in the batch for i, img in enumerate(frames): # apply frame filter on each frame img = frame_filter.apply_filter(img, depth_mask) # For every fifth frame the mask should not be applied. Hence, the # frame returned by apply_filter method should be same as original # frame if i % 5 == 0: self.assertTrue(np.array_equal(img, frames[0])) else: # Every other frame should be transformed after applying depth # mask self.assertTrue( np.array_equal(img, frames[i] * depth_mask[:, :, None]))
def classify(self, batch: FrameBatch) -> List[DepthEstimationResult]: """ sends input frames to utility method for prediction and then returns the result in DepthEstimationResult object. Arguments: FrameBatch (np.ndarray): Batch of Frames on which predictions need to be performed Returns: list of DepthEstimationResult object where each object contains [frame, depth, segmentation] value. """ frames = batch.frames_as_numpy_array() # call depth estimation on batch frames (segms, depths) = self._get_depth_estimation(frames) # process the model output and store it in DepthEstimationResult object return DepthEstimationResult.depth_result_from_batch_and_lists( batch, segms, depths)
def test_frames_as_numpy_array_should_frames_as_numpy_array(self): batch = FrameBatch(frames=create_dataframe_same(2)) expected = list(np.ones((2, 1, 1))) actual = list(batch.frames_as_numpy_array()) self.assertEqual(expected, actual)