def test_build_task_from_proto(self): task_config = { 'task_type': rv.CHIP_CLASSIFICATION, 'chip_classification_config': { 'chip_size': 500, 'class_items': [{ 'id': 1, 'name': 'car', 'color': 'red' }, { 'id': 2, 'name': 'building', 'color': 'blue' }, { 'id': 3, 'name': 'background', 'color': 'black' }] } } msg = json_format.Parse(json.dumps(task_config), TaskConfigMsg()) task = rv.TaskConfig.from_proto(msg) self.assertEqual(task.class_map.get_by_name('building').id, 2) self.assertEqual(task.chip_size, 500)
def test_build_task_from_proto(self): task_config = { 'task_type': rv.SEMANTIC_SEGMENTATION, 'semantic_segmentation_config': { 'chip_options': { 'debug_chip_probability': 0.75 }, 'chip_size': 500, 'class_items': [{ 'id': 1, 'name': 'car', 'color': 'red' }, { 'id': 2, 'name': 'building', 'color': 'blue' }] } } msg = json_format.Parse(json.dumps(task_config), TaskConfigMsg()) task = rv.TaskConfig.from_proto(msg) self.assertEqual(task.class_map.get_by_name('building').id, 2) self.assertEqual(task.chip_size, 500) self.assertEqual(task.chip_options.debug_chip_probability, 0.75)
def to_proto(self): return TaskConfigMsg( task_type=self.task_type, predict_batch_size=self.predict_batch_size, predict_package_uri=self.predict_package_uri, debug=self.debug, predict_debug_uri=self.predict_debug_uri)
def to_proto(self): struct = struct_pb2.Struct() struct['chip_size'] = self.chip_size return TaskConfigMsg(task_type=self.task_type, predict_batch_size=self.predict_batch_size, predict_package_uri=self.predict_package_uri, custom_config=struct)
def test_invalid_json(self): invalid_json_str = ''' { "taskType": "CHIP_CLASSIFICATION } ''' str_to_file(invalid_json_str, self.file_path) with self.assertRaises(ProtobufParseException): load_json_config(self.file_path, TaskConfigMsg())
def test_bogus_field(self): config = { 'taskType': 'CHIP_CLASSIFICATION', 'chipClassificationConfig': { 'classItems': [{ 'id': 1, 'name': 'car' }] }, 'bogus_field': 0 } self.write_config_file(config) with self.assertRaises(ProtobufParseException): load_json_config(self.file_path, TaskConfigMsg())
def test_valid(self): config = { 'taskType': 'CHIP_CLASSIFICATION', 'chipClassificationConfig': { 'classItems': [{ 'id': 1, 'name': 'car' }] } } self.write_config_file(config) task = load_json_config(self.file_path, TaskConfigMsg()) self.assertEqual(task.task_type, rv.CHIP_CLASSIFICATION) self.assertEqual(task.chip_classification_config.class_items[0].id, 1) self.assertEqual(task.chip_classification_config.class_items[0].name, 'car') self.assertEqual(len(task.chip_classification_config.class_items), 1)
def to_proto(self): msg = super().to_proto() chip_options = TaskConfigMsg.SemanticSegmentationConfig.ChipOptions( window_method=self.chip_options.window_method, target_classes=self.chip_options.target_classes, debug_chip_probability=self.chip_options.debug_chip_probability, negative_survival_probability=self.chip_options. negative_survival_probability, chips_per_scene=self.chip_options.chips_per_scene, target_count_threshold=self.chip_options.target_count_threshold, stride=self.chip_options.stride) conf = TaskConfigMsg.SemanticSegmentationConfig( chip_size=self.chip_size, class_items=self.class_map.to_proto(), chip_options=chip_options) msg.MergeFrom( TaskConfigMsg(semantic_segmentation_config=conf, predict_package_uri=self.predict_package_uri)) return msg
def to_proto(self): msg = super().to_proto() chip_options = TaskConfigMsg.ObjectDetectionConfig.ChipOptions( neg_ratio=self.chip_options.neg_ratio, ioa_thresh=self.chip_options.ioa_thresh, window_method=self.chip_options.window_method, label_buffer=self.chip_options.label_buffer) predict_options = TaskConfigMsg.ObjectDetectionConfig.PredictOptions( merge_thresh=self.predict_options.merge_thresh, score_thresh=self.predict_options.score_thresh) conf = TaskConfigMsg.ObjectDetectionConfig( chip_size=self.chip_size, class_items=self.class_map.to_proto(), chip_options=chip_options, predict_options=predict_options) msg.MergeFrom( TaskConfigMsg(object_detection_config=conf, predict_package_uri=self.predict_package_uri)) return msg
def to_proto(self): conf = TaskConfigMsg.ChipClassificationConfig( chip_size=self.chip_size, class_items=self.class_map.to_proto()) return TaskConfigMsg(task_type=rv.CHIP_CLASSIFICATION, chip_classification_config=conf, predict_package_uri=self.predict_package_uri)
def test_bogus_value(self): config = {'task': 'bogus_value'} self.write_config_file(config) with self.assertRaises(ProtobufParseException): load_json_config(self.file_path, TaskConfigMsg())
def to_proto(self): result = self.mock.to_proto() if result is None: return TaskConfigMsg(task_type=self.task_type, custom_config={}) else: return result
def to_proto(self): msg = TaskConfigMsg(task_type=self.task_type, custom_config={}) return msg