簡體   English   中英

在Windows上將tensorflow模型轉換為coreml模型會產生問題

[英]Converting a tensorflow model to a coreml model on windows gives issues

我在轉換自定義tf模型時遇到問題。 該模型如下所示: 張量流模型

轉換后(沒有錯誤)如下所示:

coreml模型

加法運算符在哪里?

另一個問題是轉換的輸出給了我這個:

Core ML input(s):
[name: "x_placeholder__0"
type {
  multiArrayType {
    shape: 41
    dataType: DOUBLE
  }
}
]
Core ML output(s):
[name: "softmax_prediction__0"
type {
  multiArrayType {
    shape: 2
    dataType: DOUBLE
  }
}
]

但是我的模型只有浮點值嗎? (轉換實際上將其從float32更改為float64)

有人可以回答我的問題,也許告訴我我做錯了什么嗎?

謝謝

MatMul后跟Add與innerProduct運算符相同。

請注意,innerProduct層具有“偏差”。 如果查看這些偏差值,就會發現它們與“添加”運算符中使用的值相同。 因此coremltools / tf-coreml只是將這兩個操作組合到一個單獨的層中。

MLMultiArray對象的默認數據類型為DOUBLE。 您可以將其更改為FLOAT,但不一定會更快。 使用Python的方法如下:

import coremltools  
import sys  

def update_multiarray_to_float32(feature):  
    if feature.type.HasField('multiArrayType'):  
        import coremltools.proto.FeatureTypes_pb2 as _ft  
        feature.type.multiArrayType.dataType = _ft.ArrayFeatureType.FLOAT32  

if __name__ == "__main__":  
    if len(sys.argv) != 3:  
        print "USAGE: %s <input_model_path> <output_model_path>" % sys.argv[0]  
        sys.exit(1)  

    input_model_path = sys.argv[1]  
    output_model_path = sys.argv[2]  

    spec = coremltools.utils.load_spec(input_model_path)  

    for input_feature in spec.description.input:  
        update_multiarray_to_float32(input_feature)  

    for output_feature in spec.description.output:  
        update_multiarray_to_float32(output_feature)  

    coremltools.utils.save_spec(spec, output_model_path)  

腳本由友好的Apple員工提供(請參閱https://forums.developer.apple.com/thread/84401 )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM