Comments (7)
since your input dimension length is 2, according to https://github.com/apple/coremltools/blob/master/coremltools/converters/keras/_keras2_converter.py#L227, it assumes your input shape is [Seq, D]
, and therefore returns (dim[1],)
where dim would be (126,12)
in your case.
To get around this, you could try:
inputlayer = Input(shape=(126 * 12,))
model = Reshape((126,12))(inputlayer)
model = BatchNormalization()(model)
model = Conv1D(16, 25, activation='relu')(model)
model = Flatten()(model)
model = Dense(output_size, activation='sigmoid')(model)
model = Model(inputs=inputlayer, outputs=model)
where in your coreML app, input a flattened input thats of shape (126 * 12,)
, and the mlmodel will handle the reshaping to (126, 12)
within the model.
from coremltools.
Looks like this was fixed.
from coremltools.
This seems to be happening still. I worked around the problem with the Reshape layer suggested above, but I get errors printed to the console for every prediction call at runtime.
BNNS FULLY: input batch stride doesn't make sense (32 < 32576)
For context, my first layer without the workaround is a Conv1D with input shape (4096,1).
from coremltools.
@srikris @slin07 this is definitely not fixed. I tried with the latest (master) branch and the problem appears to still be occurring. The workaround suggested by @G-mel does work but I think that the reshape operation is unnecessarily expensive on GPU.
Could this issue be reopened?
from coremltools.
@andriikrupka (126,12) is interpreted as (Seq, Channel) by CoreML. CoreML treats Seq. dimension similar to a batch dimension hence it does not hard code it into the mlmodel. So the mlmodel for the input just says 12 corresponding to the number of channels. This way you can change the value of the sequence dimension at run time when you call predict in your app. At that time CoreML can be given a multi array of 3 dimensions, which maps to (Seq,B,C). You just need to create an array of shape (126,1,12) and pass it to the predict call. In fact you can also call predict on an input which has a different seq dimension (say 100 instead of 126) by passing in (100,1,12) sized input. You do not need to change the mlmodel by adding a reshape layer.
Please see discussion in issue #142 for more details.
If in you case you only work on 126 length sequences, you can do a 2D conv such that the height dimension is 1 and the width dimension corresponds to the sequence dimension. Something like this:
inputlayer = Input(shape=(1,126,12)) #Keras interpretation: (H,W,C)
model = BatchNormalization()(inputlayer)
model = Conv2D(16, (1,25), activation='relu')(model)
model = Flatten()(model)
model = Dense(10, activation='sigmoid')(model)
model = Model(inputs=inputlayer, outputs=model)
print(model.summary())
from coremltools.
@aseemw I tried passing an input of size (100,1,12,1,1)
to @andriikrupka's model and the result was an error complaining that rank-5 inputs were not supported.
inputlayer = Input(shape=(126,12))
output_size=30
model = BatchNormalization()(inputlayer)
model = Conv1D(16, 25, activation='relu')(model)
model = Flatten()(model)
model = Dense(output_size, activation='sigmoid')(model)
model = Model(inputs=inputlayer, outputs=model)
coreml_model = coremltools.converters.keras.convert(model)
X = np.random.rand(126,1,12,1,1)
coreml_model.predict({'input1':X})
RuntimeError Traceback (most recent call last)
<ipython-input-62-692012ab6531> in <module>()
----> 1 coreml_model.predict({'input1':X})
~/dev/coreml_experiments/.venv/lib/python3.6/site-packages/coremltools/models/model.py in predict(self, data, useCPUOnly, **kwargs)
262
263 if self.__proxy__:
--> 264 return self.__proxy__.predict(data,useCPUOnly)
265 else:
266 if _macos_version() < (10, 13):
RuntimeError: {
NSLocalizedDescription = "Input input1 is an array of rank 5, but this model only supports single vector inputs (rank 1) or a sequence of batches of vectors (rank 3).";
}
from coremltools.
@vellamike I erred in my description of the input shapes. Please see comments in issue #142.
from coremltools.
Related Issues (20)
- How to profile specific CoreML operators on device HOT 4
- Change Input Shape Post-Conversion HOT 2
- Edit weight in mlprogram HOT 2
- Feature Request: Add nvidia-smi-like GPU Usage Monitoring for MPS Backend on macOS HOT 1
- ANE init failed HOT 1
- coremltools 8.0b1 linear_quantize_weights is not working for models converted with minimum_deployment_target=ct.target.iOS18 HOT 4
- Feature request to support of aten::IntImplicit ops HOT 3
- I have issue when convert the model to CoreML HOT 1
- converted model has incorrect output. HOT 1
- experimental.linear_quantize_activations with Classifier_config in ct.conver "fails" w/message 'dict' object has no attribute 'flatten' HOT 3
- Util to expose intermediate tensors as outputs HOT 2
- NameError: name 'MistralCausalLM' is not defined HOT 5
- pip install failed because numpy2.0 release includes breaking changes HOT 1
- RoPE implemetation, Torch.polar op not available in MIL requesting support HOT 2
- Sometimes, the output image will be rotated? HOT 1
- unsqueeze or expand dims not supported for complex64, HOT 2
- mb.identity breaks when complex_input.real is None
- ML Program matmul not handling 1D input correctly HOT 2
- unet Chunking not supported in coremltools>7.1 and <7.1 does not support dynamic reshape HOT 1
- `coremltools` docs - Xcode Model Preview Type for Object Detection? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coremltools.