def test_set_denotation(self): this = os.path.dirname(__file__) onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.onnx") onnx_model = load_model(onnx_file) set_denotation(onnx_model, "1", "IMAGE", dimension_denotation=["DATA_FEATURE"]) self.assertEqual(onnx_model.graph.input[0].type.denotation, "IMAGE") self.assertEqual(onnx_model.graph.input[0].type.tensor_type.shape.dim[0].denotation, "DATA_FEATURE")
def test_set_docstring_blank(self): this = os.path.dirname(__file__) onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.onnx") onnx_model = load_model(onnx_file) set_model_doc_string(onnx_model, "sample") self.assertRaises(ValueError, set_model_doc_string, onnx_model.doc_string, "sample") set_model_doc_string(onnx_model, "", True) self.assertEqual(onnx_model.doc_string, "")
def test_save_model(self): this = os.path.dirname(__file__) onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.onnx") new_onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing2.onnx") onnx_model = load_model(onnx_file) save_model(onnx_model, new_onnx_file) self.assertTrue(os.path.exists(new_onnx_file))
def convert_model_from_float_to_float16(model_path): # from onnxmltools.utils.float16_converter import convert_float_to_float16 from onnxmltools.utils import load_model, save_model from float16 import convert_float_to_float16 onnx_model = load_model(model_path) new_onnx_model = convert_float_to_float16(onnx_model) save_model(new_onnx_model, 'new_fp16_model.onnx') return os.path.join(os.getcwd(), "new_fp16_model.onnx")
def test_model_setters(self): this = os.path.dirname(__file__) onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.onnx") onnx_model = load_model(onnx_file) set_model_version(onnx_model, 2) set_model_domain(onnx_model, "com.sample") set_model_doc_string(onnx_model, "Sample docstring") self.assertEqual(onnx_model.model_version, 2) self.assertEqual(onnx_model.domain, "com.sample") self.assertEqual(onnx_model.doc_string, "Sample docstring")
def test_save_text(self): this = os.path.dirname(__file__) onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.onnx") onnx_model = load_model(onnx_file) json_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.json") json_file_new = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing_new.json") save_text(onnx_model, json_file_new) filecmp.clear_cache() content1 = self._parseEOL(json_file) content2 = self._parseEOL(json_file_new) self.assertTrue(content1 == content2, "Output file from save_text is different than reference output.")
def test_save_text(self): this = os.path.dirname(__file__) onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.onnx") onnx_model = load_model(onnx_file) if StrictVersion(onnx.__version__) < StrictVersion('1.4.0'): json_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.json") else: json_file = os.path.join( this, "models", "coreml_OneHotEncoder_BikeSharing_Op9.json") json_file_new = os.path.join( this, "models", "coreml_OneHotEncoder_BikeSharing_new.json") save_text(onnx_model, json_file_new) try: filecmp.clear_cache() except AttributeError: # Only available in Python 3 pass content1 = self._parseEOL(json_file) content2 = self._parseEOL(json_file_new) self.assertTrue( content1 == content2, "Output file from save_text is different than reference output.")
def test_load_model(self): this = os.path.dirname(__file__) onnx_file = os.path.join(this, "models", "coreml_OneHotEncoder_BikeSharing.onnx") onnx_model = load_model(onnx_file) self.assertTrue(onnx_model is not None)