Code Monkey home page Code Monkey logo

Comments (7)

hi-mel avatar hi-mel commented on August 16, 2024 4

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.

srikris avatar srikris commented on August 16, 2024

Looks like this was fixed.

from coremltools.

brodney avatar brodney commented on August 16, 2024

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.

vellamike avatar vellamike commented on August 16, 2024

@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.

aseemw avatar aseemw commented on August 16, 2024

@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.

vellamike avatar vellamike commented on August 16, 2024

@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.

aseemw avatar aseemw commented on August 16, 2024

@vellamike I erred in my description of the input shapes. Please see comments in issue #142.

from coremltools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.