I'm currently working in a collaboration. My task is to convert an h5-file, which was generated by a neural network with tensorflow, to an coreML. Additionally I should implement it to my Xcode Project.
The Input is a two dimensional array of 21 Floats:
input = [[0.5, 0.4, ...]]
The output should be a Float between 0 and 1.
I've tried a lot but as far as I know the main issue is that coreML supports just the classification of a picture. I didn't find any clue how to convert an h5 to an coreML with this specific type of input and output as mentioned. Can anybody help? Thanks a lot!
Edit
This is my code. I'm confused because once I read that I just have to name the input and output instead of defining the variable as an MLMultiArray. I guess this is my main issue. But didn't catch how to define the input as an MLMultiArray.
from keras.models import load_model
import coremltools
coreml_model = coremltools.converters.keras.convert('modelv.h5',
input_names=['data'],
output_names=['output'],
)
coreml_model.save('PredictionModel.mlmodel')
When I run the code I'm getting this following message from the compiler.
runfile('/Path/Neuronal Network')
Traceback (most recent call last):
File "/Path/ Neuronal Network/Converter.py", line 20, in <module>
output_names='output',
File "/path/", line 804, in convert
use_float_arraytype=use_float_arraytype)
File "/Path/opt/anaconda3/lib/python3.7/site-packages/coremltools/converters/keras/_keras_converter.py", line 585, in convertToSpec
use_float_arraytype=use_float_arraytype)
File "/Path/opt/anaconda3/lib/python3.7/site-packages/coremltools/converters/keras/_keras2_converter.py", line 328, in _convert
graph.build()
File "/Path/opt/anaconda3/lib/python3.7/site-packages/coremltools/converters/keras/_topology2.py", line 740, in build
self.make_input_layers()
File "/Path/opt/anaconda3/lib/python3.7/site-packages/coremltools/converters/keras/_topology2.py", line 169, in make_input_layers
if isinstance(kl, InputLayer) and kl.input == ts:
File "/Path/opt/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 765, in __bool__
self._disallow_bool_casting()
File "/Path/opt/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 534, in _disallow_bool_casting
self._disallow_in_graph_mode("using a `tf.Tensor` as a Python `bool`")
File "/Path/opt/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py", line 523, in _disallow_in_graph_mode
" this function with @tf.function.".format(task))
OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.