apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.44k stars 643 forks source link

RuntimeError when performing prediction on a sound classification model. #1862

Closed josetorronteras closed 1 year ago

josetorronteras commented 1 year ago

🐞Describing the bug

I have a sound classification model trained with CreateML. I export it correctly to a jupyter notebook using your library.

The bug occurs when I try to make a prediction from a sound or directly from a random numpy array as it appears in your documentation.

Stack Trace

RuntimeError                              Traceback (most recent call last)
Cell In[66], line 2
      1 input_shape = (15600,)
----> 2 output_dict = mlmodel.predict({'audioSamples': np.random.rand(*input_shape)})

File [~/Library/Python/3.9/lib/python/site-packages/coremltools/models/model.py:518](https://file+.vscode-resource.vscode-cdn.net/Users/username/Code/birdclef/~/Library/Python/3.9/lib/python/site-packages/coremltools/models/model.py:518), in MLModel.predict(self, data)
    516     # TODO: remove the following call when this is fixed: rdar://92239209
    517     self._update_float16_multiarray_input_to_float32(data)
--> 518     return self.__proxy__.predict(data)
    519 else:
    520     if _macos_version() < (10, 13):

RuntimeError: {
    NSLocalizedDescription = "Failed to evaluate model 0 in pipeline";
    NSUnderlyingError = "Error Domain=com.apple.CoreML Code=1 \"(null)\"";
}

To Reproduce

print(mlmodel.get_spec().description.input)
#[name: "audioSamples"
#shortDescription: "Input audio samples to be classified"
#type {
#  multiArrayType {
#      shape: 15600
#      dataType: FLOAT32
#      shapeRange {
#        sizeRanges {
#          lowerBound: 8000
#          upperBound: 240000
#        }
#      }
#    }
#  }
#]

input_shape = (15600,)
output_dict = mlmodel.predict({'audioSamples': np.random.rand(*input_shape)})

System environment (please complete the following information):

Additional context

I am following this doc: https://coremltools.readme.io/docs/model-prediction#multi-array-prediction

Thanks. Jose

jakesabathia2 commented 1 year ago

Can you attach a reproducible script which creates a simple model that can get the same error?