def __init__(self): self.platform = sys.platform self.tf_version = utils.get_tf_version() self.opset = int(os.environ.get("TF2ONNX_TEST_OPSET", constants.PREFERRED_OPSET)) self.target = os.environ.get("TF2ONNX_TEST_TARGET", ",".join(constants.DEFAULT_TARGET)).split(',') self.backend = os.environ.get("TF2ONNX_TEST_BACKEND", "onnxruntime") self.backend_version = self._get_backend_version() self.log_level = logging.WARNING self.temp_dir = utils.get_temp_directory()
def __init__(self): self.platform = sys.platform self.tf_version = self._get_tf_version() self.opset = int(os.environ.get("TF2ONNX_TEST_OPSET", 7)) self.target = os.environ.get("TF2ONNX_TEST_TARGET", ",".join(DEFAULT_TARGET)).split(',') self.backend = os.environ.get("TF2ONNX_TEST_BACKEND", "onnxruntime") self.backend_version = self._get_backend_version() self.is_debug_mode = False self.temp_dir = utils.get_temp_directory()
def __init__(self): self.platform = sys.platform self.tf_version = tf_utils.get_tf_version() self.opset = int(os.environ.get("TF2ONNX_TEST_OPSET", constants.PREFERRED_OPSET)) self.target = os.environ.get("TF2ONNX_TEST_TARGET", ",".join(constants.DEFAULT_TARGET)).split(',') self.backend = os.environ.get("TF2ONNX_TEST_BACKEND", "onnxruntime") self.skip_tflite_tests = os.environ.get("TF2ONNX_SKIP_TFLITE_TESTS", "FALSE").upper() == "TRUE" self.skip_tf_tests = os.environ.get("TF2ONNX_SKIP_TF_TESTS", "FALSE").upper() == "TRUE" self.run_tfl_consistency_test = os.environ.get("TF2ONNX_RUN_TFL_CONSISTENCY_TEST", "FALSE").upper() == "TRUE" self.backend_version = self._get_backend_version() self.log_level = logging.WARNING self.temp_dir = utils.get_temp_directory()
# contrib ops are registered only when the module is imported, the following import statement is needed, # otherwise tf runtime error will show up when the tf model is restored from pb file because of un-registered ops. try: import tensorflow.contrib.rnn # pylint: disable=unused-import except: # pylint: disable=bare-except # not needed for tf-2.0 pass from tf2onnx import tf_loader, logging, optimizer, utils, tf_utils from tf2onnx.tfonnx import process_tf_graph from tf2onnx.tf_loader import tf_session, tf_reset_default_graph from tf2onnx.graph import ExternalTensorStorage logger = logging.getLogger("run_pretrained") TEMP_DIR = os.path.join(utils.get_temp_directory(), "run_pretrained") PERFITER = 1000 def get_beach(shape): """Get beach image as input.""" resize_to = shape[1:3] path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "beach.jpg") img = PIL.Image.open(path) img = img.resize(resize_to, PIL.Image.ANTIALIAS) img_np = np.array(img).astype(np.float32) img_np = np.stack([img_np] * shape[0], axis=0).reshape(shape) return img_np / 255