本文整理匯總了Python中tfcoreml.convert方法的典型用法代碼示例。如果您正苦於以下問題:Python tfcoreml.convert方法的具體用法?Python tfcoreml.convert怎麽用?Python tfcoreml.convert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tfcoreml
的用法示例。
在下文中一共展示了tfcoreml.convert方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_googlenet_resnet_v2
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_googlenet_resnet_v2(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception_resnet_v2_2016_08_30_frozen.pb.tar.gz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'inception_resnet_v2_2016_08_30_frozen.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'inception_resnet_v2_2016_08_30_frozen.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['InceptionResnetV2/Logits/Predictions:0'],
input_name_shape_dict = {'input:0':[1,299,299,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'InceptionResnetV2/Logits/Predictions:0',
img_size = 299)
示例2: test_googlenet_v1_slim
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_googlenet_v1_slim(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception_v1_2016_08_28_frozen.pb.tar.gz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'inception_v1_2016_08_28_frozen.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'inception_v1_2016_08_28_frozen.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['InceptionV1/Logits/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,244,224,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'InceptionV1/Logits/Predictions/Softmax:0',
img_size = 224)
示例3: test_googlenet_v2_slim
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_googlenet_v2_slim(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception_v2_2016_08_28_frozen.pb.tar.gz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'inception_v2_2016_08_28_frozen.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'inception_v2_2016_08_28_frozen.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['InceptionV2/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,244,224,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'InceptionV2/Predictions/Softmax:0',
img_size = 224)
示例4: test_mobilenet_v1_100_224
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_mobilenet_v1_100_224(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_1.0_224_frozen.tgz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_1.0_224/frozen_graph.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_1.0_224.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['MobilenetV1/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,224,224,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'MobilenetV1/Predictions/Softmax:0',
img_size = 224)
示例5: test_mobilenet_v2_100_224
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_mobilenet_v2_100_224(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_1.0_224_frozen.tgz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_1.0_224/frozen_graph.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_1.0_224.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['MobilenetV1/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,224,224,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'MobilenetV1/Predictions/Softmax:0',
img_size = 224)
示例6: test_mobilenet_v1_75_192
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_mobilenet_v1_75_192(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_0.75_192_frozen.tgz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_0.75_192/frozen_graph.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_0.75_192.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['MobilenetV1/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,192,192,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'MobilenetV1/Predictions/Softmax:0',
img_size = 192)
示例7: test_googlenet_v1_slim
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_googlenet_v1_slim(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception_v1_2016_08_28_frozen.pb.tar.gz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'inception_v1_2016_08_28_frozen.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'inception_v1_2016_08_28_frozen.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['InceptionV1/Logits/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,224,224,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'InceptionV1/Logits/Predictions/Softmax:0',
img_size = 224)
示例8: test_googlenet_v1_slim_with_img_format
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_googlenet_v1_slim_with_img_format(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception_v1_2016_08_28_frozen.pb.tar.gz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'inception_v1_2016_08_28_frozen.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'inception_v1_2016_08_28_frozen.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['InceptionV1/Logits/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,224,224,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0,
tf_image_format='NHWC')
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'InceptionV1/Logits/Predictions/Softmax:0',
img_size = 224)
示例9: test_googlenet_v4_slim
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_googlenet_v4_slim(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception_v4_2016_09_09_frozen.pb.tar.gz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'inception_v4_2016_09_09_frozen.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'inception_v4_2016_09_09_frozen.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['InceptionV4/Logits/Predictions:0'],
input_name_shape_dict = {'input:0':[1,299,299,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'InceptionV4/Logits/Predictions:0',
img_size = 299)
示例10: _convert_to_coreml
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def _convert_to_coreml(tf_model_path, mlmodel_path, input_name_shape_dict,
output_names, add_custom_layers=False, custom_conversion_functions={},
minimum_ios_deployment_target='12',
image_input_names=None,is_bgr=False, image_scale=1., red_bias=0.,
blue_bias=0., green_bias=0., gray_bias=0.):
""" Convert and return the coreml model from the Tensorflow
"""
model = tf_converter.convert(tf_model_path=tf_model_path,
mlmodel_path=mlmodel_path,
output_feature_names=output_names,
input_name_shape_dict=input_name_shape_dict,
add_custom_layers=add_custom_layers,
custom_conversion_functions=custom_conversion_functions,
minimum_ios_deployment_target=minimum_ios_deployment_target,
image_input_names=image_input_names,
image_scale=image_scale,
is_bgr=is_bgr,
red_bias=red_bias,
blue_bias=blue_bias,
green_bias=green_bias,
gray_bias=gray_bias)
return model
示例11: convert_to_coreml
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def convert_to_coreml(inference_graph_path, output_path):
"""Convert a tensorflow inference graph to Core ML model.
This assumes mobilenet preprocessing.
Args:
inference_graph_path (str): path to a tensorflow frozen graph .pb file
output_path (str): output path for .mlmodel file
"""
tfcoreml.convert(
tf_model_path=inference_graph_path,
mlmodel_path=output_path,
output_feature_names=['concat:0', 'concat_1:0'],
input_name_shape_dict={'Preprocessor/sub:0': [1, 300, 300, 3]},
image_input_names='Preprocessor/sub:0',
image_scale=2.0 / 255.0,
red_bias=-1.0,
green_bias=-1.0,
blue_bias=-1.0
)
示例12: test_inception_v3_slim
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_inception_v3_slim(self):
#Download model
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'inception_v3_2016_08_28_frozen.pb')
#Convert to coreml
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'inception_v3_2016_08_28.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['InceptionV3/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,299,299,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'InceptionV3/Predictions/Softmax:0',
img_size = 299)
示例13: test_googlenet_v1_nonslim
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_googlenet_v1_nonslim(self):
#Download model
url = 'https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'tensorflow_inception_graph.pb')
#Convert to coreml
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'googlenet_v1_nonslim.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['softmax2:0'],
input_name_shape_dict = {'input:0':[1,224,224,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'softmax2:0',
img_size = 224)
示例14: test_mobilenet_v1_50_160
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_mobilenet_v1_50_160(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_0.50_160_frozen.tgz'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_0.50_160/frozen_graph.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'mobilenet_v1_0.50_160.mlmodel')
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['MobilenetV1/Predictions/Softmax:0'],
input_name_shape_dict = {'input:0':[1,160,160,3]},
image_input_names = ['input:0'],
red_bias = -1,
green_bias = -1,
blue_bias = -1,
image_scale = 2.0/255.0)
#Test predictions on an image
self._test_coreml_model_image_input(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensor_name = 'input:0',
output_tensor_name = 'MobilenetV1/Predictions/Softmax:0',
img_size = 160)
#@unittest.skip("Failing GPU backend: related to https://github.com/tf-coreml/tf-coreml/issues/26")
示例15: test_style_transfer
# 需要導入模塊: import tfcoreml [as 別名]
# 或者: from tfcoreml import convert [as 別名]
def test_style_transfer(self):
url = 'https://storage.googleapis.com/download.tensorflow.org/models/stylize_v1.zip'
tf_model_dir = _download_file(url = url)
tf_model_path = os.path.join(TMP_MODEL_DIR, 'stylize_quantized.pb')
mlmodel_path = os.path.join(TMP_MODEL_DIR, 'stylize_quantized.mlmodel')
# ? style transfer image size and style number?
mlmodel = tf_converter.convert(
tf_model_path = tf_model_path,
mlmodel_path = mlmodel_path,
output_feature_names = ['Squeeze:0'],
input_name_shape_dict = {'input:0':[1,256,256,3], 'style_num:0':[26]})
# Test predictions on an image
input_tensors = [('input:0',[1,256,256,3]),
('style_num:0',[26])]
self.err_thresh = 0.5
self._test_tf_model(
tf_model_path = tf_model_path,
coreml_model = mlmodel,
input_tensors = input_tensors,
output_tensor_names = ['Squeeze:0'],
data_modes = ['image', 'onehot_0'],
delta = 1e-2,
use_cpu_only = True,
scale = 1,
bias = 0,
img_size = 256,
sequence_inputs = {'style_num:0'})