coremltools converting GRU layer called with initial_stateCalling an external command in PythonConverting string into datetimeConvert bytes to a string?3D Convolutional Neural Network input shapeOnly layers of same output shape can be merged using sum mode. Layer shapesCoreMLTools Keras simple Sequential Linear Regression model export error ('module' object has no attribute 'mobilenet')Issue with adding a SimpleRNN or LSTM layer in KerasProblems with Seq2Seq model using RNN layer and GRU cells in KerasKeras ValueError: Unknown layer:name, when trying to load model to another platformValueError: Graph disconnected When I was trying build Timedistrubuted Model in keras

Biological Blimps: Propulsion

Picking the different solutions to the time independent Schrodinger eqaution

How to explain what's wrong with this application of the chain rule?

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

A social experiment. What is the worst that can happen?

Has any country ever had 2 former presidents in jail simultaneously?

How much character growth crosses the line into breaking the character

Open a doc from terminal, but not by its name

What is the evidence for the "tyranny of the majority problem" in a direct democracy context?

Pre-mixing cryogenic fuels and using only one fuel tank

How do apertures which seem too large to physically fit work?

Multiplicative persistence

Angel of Condemnation - Exile creature with second ability

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

Moving brute-force search to FPGA

Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?

Can I say "fingers" when referring to toes?

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

Using substitution ciphers to generate new alphabets in a novel

Mimic lecturing on blackboard, facing audience

Does an advisor owe his/her student anything? Will an advisor keep a PhD student only out of pity?

What should you do when eye contact makes your subordinate uncomfortable?

Is this toilet slogan correct usage of the English language?

Is there a RAID 0 Equivalent for RAM?



coremltools converting GRU layer called with initial_state


Calling an external command in PythonConverting string into datetimeConvert bytes to a string?3D Convolutional Neural Network input shapeOnly layers of same output shape can be merged using sum mode. Layer shapesCoreMLTools Keras simple Sequential Linear Regression model export error ('module' object has no attribute 'mobilenet')Issue with adding a SimpleRNN or LSTM layer in KerasProblems with Seq2Seq model using RNN layer and GRU cells in KerasKeras ValueError: Unknown layer:name, when trying to load model to another platformValueError: Graph disconnected When I was trying build Timedistrubuted Model in keras













0















In my Keras model I pass an initial_state parameter when calling the GRU layer. My app keeps track of the encoder_state and passes it back to the model when I want to predict on a new input.



encoder_output, encoder_state = GRU(latent_dim,return_state=True,name='gru')(encoder_input,initial_state=state)


All is swell when running inference with Keras but the problem comes when I try to convert to a coreML model.



0 : input_56, <keras.engine.topology.InputLayer object at 0x7f5e21159668>
1 : input_57, <keras.engine.topology.InputLayer object at 0x7f5e21159630>
2 : gru, <keras.layers.recurrent.GRU object at 0x7f5e2116a9e8>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras2_converter.py", line 316, in _convert
converter_func(builder, layer, input_names, output_names, keras_layer)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_layers2.py", line 1058, in convert_gru
reverse_input = reverse_input)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/models/neural_network/builder.py", line 1530, in add_gru
spec_layer_params.inputVectorSize = input_size
TypeError: (None, 256) has type tuple, but expected one of: int, long


When I check the shape of this Keras layer I get what I expect. The first tuple is the encoder_input shape and the second is the initial_state shape.



print(encoder.get_layer('gru').input_shape)
>>> [(None, 1, 1536), (None, 256)]


Looking into the coreML code for convert_gru tells me it just takes the last entry in the input_shape as the input_size, which in my case is (None, 256).



def convert_gru(builder, layer, input_names, output_names, keras_layer):

...

input_size = keras_layer.input_shape[-1]


Does anyone know how I can pass an initial_state to my GRU layer and have coreml convert it for me?










share|improve this question







New contributor




Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • In Core ML you always need to pass in the state manually. Try converting the model without the initial_state argument.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Thanks! Any chance you can elaborate on passing the state manually to the coreML model? I can't seem to find any concrete examples.

    – Lewis Bails
    yesterday











  • To make a prediction with the Core ML model, you'd call let output = model.prediction(input: xxx, gru_state: xxx). I'm not sure what the name of the GRU state input is, so it's probably not gru_state, but you get the idea: the state must always be passed as an input. The output of the model also contains the updated GRU state. You would pass that into the model the next time around, etc. In other words: Core ML does not keep any GRU state inside the model, you have to manage this yourself.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Makes sense. I'll give it a go. Thanks for the help.

    – Lewis Bails
    yesterday















0















In my Keras model I pass an initial_state parameter when calling the GRU layer. My app keeps track of the encoder_state and passes it back to the model when I want to predict on a new input.



encoder_output, encoder_state = GRU(latent_dim,return_state=True,name='gru')(encoder_input,initial_state=state)


All is swell when running inference with Keras but the problem comes when I try to convert to a coreML model.



0 : input_56, <keras.engine.topology.InputLayer object at 0x7f5e21159668>
1 : input_57, <keras.engine.topology.InputLayer object at 0x7f5e21159630>
2 : gru, <keras.layers.recurrent.GRU object at 0x7f5e2116a9e8>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras2_converter.py", line 316, in _convert
converter_func(builder, layer, input_names, output_names, keras_layer)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_layers2.py", line 1058, in convert_gru
reverse_input = reverse_input)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/models/neural_network/builder.py", line 1530, in add_gru
spec_layer_params.inputVectorSize = input_size
TypeError: (None, 256) has type tuple, but expected one of: int, long


When I check the shape of this Keras layer I get what I expect. The first tuple is the encoder_input shape and the second is the initial_state shape.



print(encoder.get_layer('gru').input_shape)
>>> [(None, 1, 1536), (None, 256)]


Looking into the coreML code for convert_gru tells me it just takes the last entry in the input_shape as the input_size, which in my case is (None, 256).



def convert_gru(builder, layer, input_names, output_names, keras_layer):

...

input_size = keras_layer.input_shape[-1]


Does anyone know how I can pass an initial_state to my GRU layer and have coreml convert it for me?










share|improve this question







New contributor




Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • In Core ML you always need to pass in the state manually. Try converting the model without the initial_state argument.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Thanks! Any chance you can elaborate on passing the state manually to the coreML model? I can't seem to find any concrete examples.

    – Lewis Bails
    yesterday











  • To make a prediction with the Core ML model, you'd call let output = model.prediction(input: xxx, gru_state: xxx). I'm not sure what the name of the GRU state input is, so it's probably not gru_state, but you get the idea: the state must always be passed as an input. The output of the model also contains the updated GRU state. You would pass that into the model the next time around, etc. In other words: Core ML does not keep any GRU state inside the model, you have to manage this yourself.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Makes sense. I'll give it a go. Thanks for the help.

    – Lewis Bails
    yesterday













0












0








0








In my Keras model I pass an initial_state parameter when calling the GRU layer. My app keeps track of the encoder_state and passes it back to the model when I want to predict on a new input.



encoder_output, encoder_state = GRU(latent_dim,return_state=True,name='gru')(encoder_input,initial_state=state)


All is swell when running inference with Keras but the problem comes when I try to convert to a coreML model.



0 : input_56, <keras.engine.topology.InputLayer object at 0x7f5e21159668>
1 : input_57, <keras.engine.topology.InputLayer object at 0x7f5e21159630>
2 : gru, <keras.layers.recurrent.GRU object at 0x7f5e2116a9e8>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras2_converter.py", line 316, in _convert
converter_func(builder, layer, input_names, output_names, keras_layer)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_layers2.py", line 1058, in convert_gru
reverse_input = reverse_input)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/models/neural_network/builder.py", line 1530, in add_gru
spec_layer_params.inputVectorSize = input_size
TypeError: (None, 256) has type tuple, but expected one of: int, long


When I check the shape of this Keras layer I get what I expect. The first tuple is the encoder_input shape and the second is the initial_state shape.



print(encoder.get_layer('gru').input_shape)
>>> [(None, 1, 1536), (None, 256)]


Looking into the coreML code for convert_gru tells me it just takes the last entry in the input_shape as the input_size, which in my case is (None, 256).



def convert_gru(builder, layer, input_names, output_names, keras_layer):

...

input_size = keras_layer.input_shape[-1]


Does anyone know how I can pass an initial_state to my GRU layer and have coreml convert it for me?










share|improve this question







New contributor




Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












In my Keras model I pass an initial_state parameter when calling the GRU layer. My app keeps track of the encoder_state and passes it back to the model when I want to predict on a new input.



encoder_output, encoder_state = GRU(latent_dim,return_state=True,name='gru')(encoder_input,initial_state=state)


All is swell when running inference with Keras but the problem comes when I try to convert to a coreML model.



0 : input_56, <keras.engine.topology.InputLayer object at 0x7f5e21159668>
1 : input_57, <keras.engine.topology.InputLayer object at 0x7f5e21159630>
2 : gru, <keras.layers.recurrent.GRU object at 0x7f5e2116a9e8>
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_keras2_converter.py", line 316, in _convert
converter_func(builder, layer, input_names, output_names, keras_layer)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/converters/keras/_layers2.py", line 1058, in convert_gru
reverse_input = reverse_input)
File "/home/lbai/.local/lib/python3.6/site-packages/coremltools/models/neural_network/builder.py", line 1530, in add_gru
spec_layer_params.inputVectorSize = input_size
TypeError: (None, 256) has type tuple, but expected one of: int, long


When I check the shape of this Keras layer I get what I expect. The first tuple is the encoder_input shape and the second is the initial_state shape.



print(encoder.get_layer('gru').input_shape)
>>> [(None, 1, 1536), (None, 256)]


Looking into the coreML code for convert_gru tells me it just takes the last entry in the input_shape as the input_size, which in my case is (None, 256).



def convert_gru(builder, layer, input_names, output_names, keras_layer):

...

input_size = keras_layer.input_shape[-1]


Does anyone know how I can pass an initial_state to my GRU layer and have coreml convert it for me?







python tensorflow keras coreml coremltools






share|improve this question







New contributor




Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Lewis BailsLewis Bails

11




11




New contributor




Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Lewis Bails is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • In Core ML you always need to pass in the state manually. Try converting the model without the initial_state argument.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Thanks! Any chance you can elaborate on passing the state manually to the coreML model? I can't seem to find any concrete examples.

    – Lewis Bails
    yesterday











  • To make a prediction with the Core ML model, you'd call let output = model.prediction(input: xxx, gru_state: xxx). I'm not sure what the name of the GRU state input is, so it's probably not gru_state, but you get the idea: the state must always be passed as an input. The output of the model also contains the updated GRU state. You would pass that into the model the next time around, etc. In other words: Core ML does not keep any GRU state inside the model, you have to manage this yourself.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Makes sense. I'll give it a go. Thanks for the help.

    – Lewis Bails
    yesterday

















  • In Core ML you always need to pass in the state manually. Try converting the model without the initial_state argument.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Thanks! Any chance you can elaborate on passing the state manually to the coreML model? I can't seem to find any concrete examples.

    – Lewis Bails
    yesterday











  • To make a prediction with the Core ML model, you'd call let output = model.prediction(input: xxx, gru_state: xxx). I'm not sure what the name of the GRU state input is, so it's probably not gru_state, but you get the idea: the state must always be passed as an input. The output of the model also contains the updated GRU state. You would pass that into the model the next time around, etc. In other words: Core ML does not keep any GRU state inside the model, you have to manage this yourself.

    – Matthijs Hollemans
    yesterday











  • @MatthijsHollemans Makes sense. I'll give it a go. Thanks for the help.

    – Lewis Bails
    yesterday
















In Core ML you always need to pass in the state manually. Try converting the model without the initial_state argument.

– Matthijs Hollemans
yesterday





In Core ML you always need to pass in the state manually. Try converting the model without the initial_state argument.

– Matthijs Hollemans
yesterday













@MatthijsHollemans Thanks! Any chance you can elaborate on passing the state manually to the coreML model? I can't seem to find any concrete examples.

– Lewis Bails
yesterday





@MatthijsHollemans Thanks! Any chance you can elaborate on passing the state manually to the coreML model? I can't seem to find any concrete examples.

– Lewis Bails
yesterday













To make a prediction with the Core ML model, you'd call let output = model.prediction(input: xxx, gru_state: xxx). I'm not sure what the name of the GRU state input is, so it's probably not gru_state, but you get the idea: the state must always be passed as an input. The output of the model also contains the updated GRU state. You would pass that into the model the next time around, etc. In other words: Core ML does not keep any GRU state inside the model, you have to manage this yourself.

– Matthijs Hollemans
yesterday





To make a prediction with the Core ML model, you'd call let output = model.prediction(input: xxx, gru_state: xxx). I'm not sure what the name of the GRU state input is, so it's probably not gru_state, but you get the idea: the state must always be passed as an input. The output of the model also contains the updated GRU state. You would pass that into the model the next time around, etc. In other words: Core ML does not keep any GRU state inside the model, you have to manage this yourself.

– Matthijs Hollemans
yesterday













@MatthijsHollemans Makes sense. I'll give it a go. Thanks for the help.

– Lewis Bails
yesterday





@MatthijsHollemans Makes sense. I'll give it a go. Thanks for the help.

– Lewis Bails
yesterday












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Lewis Bails is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280872%2fcoremltools-converting-gru-layer-called-with-initial-state%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes








Lewis Bails is a new contributor. Be nice, and check out our Code of Conduct.









draft saved

draft discarded


















Lewis Bails is a new contributor. Be nice, and check out our Code of Conduct.












Lewis Bails is a new contributor. Be nice, and check out our Code of Conduct.











Lewis Bails is a new contributor. Be nice, and check out our Code of Conduct.














Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280872%2fcoremltools-converting-gru-layer-called-with-initial-state%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현