error in keras.convert from VAE

I've modified the keras VAE example code for my data, and I'd like to import it into CoreML. I managed to convert a simple AE the other day using keras.convert, but I'm getting the following error withe VAE example:

"NameError: global name 'batch_size' is not defined"


Any thoughts on how to fix it? Is it possible?

I'm using keras with tensorflow backend.


Thanks in advance (very new to this!),


J.

Replies

UPDATE: I got farther by removing all the variables from the python code and entering the associated values directly into the keras/tensorflow functions. However, now it fails on:

ValueError: Unknown layer: CustomVariationalLayer

...which is at least clear—coremltools isn't able to convert a model with custom layers. Fair enough.

(Of course, I'm happy to be wrong about this!)

I am not familiar to VAE, but by a glance at the code https://github.com/fchollet/keras/blob/master/examples/variational_autoencoder.py#L56, the problematic layer is just a loss layer. It is not used for feed forward, so you may safely remove it in you python code before passing it to coremltools.


> ...which is at least clear—coremltools isn't able to convert a model with custom layers. Fair enough.


Even if the custom layer is used in feed forward, in some case you can look into the coreml protobuf files definitions and find a coresponding layer, and then implement the conversion yourself (modify coremltools source code. I have tried it.). Coremltools for Keras is not fully exploiting the capabilities of coreml. But in some cases it may be impossible.