hollance / YOLO-CoreML-MPSNNGraph

Tiny YOLO for iOS implemented using CoreML but also using the new MPS graph API.
MIT License
933 stars 252 forks source link

AttributeError: 'module' object has no attribute 'NetGraph' #22

Closed kellum42 closed 6 years ago

kellum42 commented 6 years ago

Thanks for the amazing tutorial!

I'm trying to convert tiny yolo to a coreml .mlmodel. After I load the model and weights, I try to convert it and get this error. I'm running python2.7, keras 2.1.3, tensorflow 1.5.0, and coremltools 0.7. Any help would be greatly appreciated! Thanks


AttributeError Traceback (most recent call last)

in () 84 85 if __name__ == "__main__": ---> 86 main() in main() 78 model.load_weights(weights) 79 print("weights loaded") ---> 80 convert_to_coreml(model) 81 print("converted") 82 in convert_to_coreml(model) 57 image_input_names='image', 58 output_names='grid', ---> 59 image_scale=1/255.) 60 /Users/travis/coreml/lib/python2.7/site-packages/coremltools/converters/keras/_keras_converter.pyc in convert(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, model_precision, predicted_probabilities_output, add_custom_layers, custom_conversion_functions) 720 predicted_probabilities_output, 721 add_custom_layers, --> 722 custom_conversion_functions=custom_conversion_functions) 723 724 return _MLModel(spec) /Users/travis/coreml/lib/python2.7/site-packages/coremltools/converters/keras/_keras_converter.pyc in convertToSpec(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, model_precision, predicted_probabilities_output, add_custom_layers, custom_conversion_functions) 525 predicted_probabilities_output=predicted_probabilities_output, 526 add_custom_layers=add_custom_layers, --> 527 custom_conversion_functions=custom_conversion_functions) 528 else: 529 raise RuntimeError( /Users/travis/coreml/lib/python2.7/site-packages/coremltools/converters/keras/_keras2_converter.pyc in _convert(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, predicted_probabilities_output, add_custom_layers, custom_conversion_functions) 170 171 from topology2 import NetGraph --> 172 173 # Build network graph to represent Keras model 174 graph = _topology2.NetGraph(model) AttributeError: 'module' object has no attribute 'NetGraph'
hollance commented 6 years ago

That's probably a version mismatch. Make sure to use the correct Keras and TF versions with coremltools.

kellum42 commented 6 years ago

That worked! Python3 and python2.7 were running a different version of keras and tensorflow. I removed and reinstalled the same versions and it worked perfectly. A similar issue can be seen here. https://github.com/keras-team/keras/issues/7007