我有一個訓練有素的scikit-learn模型,它使用多輸出決策樹(作爲RandomForestRegressor
)。由於內置了多輸出行爲,因此沒有對隨機森林迴歸模型顯式進行自定義配置以啓用多輸出行爲。基本上,只要您將多輸出訓練數據放入模型中,模型將在幕後切換到多輸出模式。scikit-learn:將多輸出決策樹轉換爲CoreML模型
此外,RandomForestRegressor
是CoreML轉換腳本提供的支持的轉換器。然而,在轉換過程中,我得到這個錯誤瓦特/堆棧跟蹤:
ValueError: Expected only 1 output in the scikit-learn tree.
Traceback (most recent call last):
File "/Users/user0/Desktop/model_convert.py", line 7, in <module>
coreml_model = sklearn_to_ml.convert(model)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_converter.py", line 146, in convert
sk_obj, input_features, output_feature_names, class_labels = None)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_converter_internal.py", line 297, in _convert_sklearn_model
last_spec = last_sk_m.convert(last_sk_obj, current_input_features, output_features)._spec
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_random_forest_regressor.py", line 53, in convert
return _MLModel(_convert_tree_ensemble(model, feature_names, target))
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 195, in convert_tree_ensemble
scaling = scaling, mode = mode, n_classes = n_classes, tree_index = tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 68, in _recurse
_recurse(coreml_tree, scikit_tree, tree_id, left_child_id, scaling, mode, n_classes, tree_index)
File "/Library/Python/2.7/site-packages/coremltools/converters/sklearn/_tree_ensemble.py", line 75, in _recurse
raise ValueError('Expected only 1 output in the scikit-learn tree.')
ValueError: Expected only 1 output in the scikit-learn tree.
簡單的轉換代碼如下:
from coremltools.converters import sklearn as sklearn_to_ml
from sklearn.externals import joblib
model = joblib.load("ms5000.pkl")
print("Converting model")
coreml_model = sklearn_to_ml.convert(model)
print("Saving CoreML model")
coreml_model.save("ms5000.mlmodel")
我能做些什麼,以使CoreML轉換腳本處理多輸出決策樹?是否可以對現有腳本進行更改,而不用完全重新創建新腳本的輪子?