How to convert resnet50 into coreml model? - tensorflow

How to convert resnet50 network written in eager_execution mode into coreml?
Here is the tf resnet50 implementation:
https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/contrib/eager/python/examples/resnet50/resnet50.py

At this point, coremltools and tfcoreml don't handle eager mode. You'll need to convert your TF model to a "frozen" .pb graph file first, and then you can use tfcoreml to convert it to Core ML.
If you can't turn your model into a frozen graph file, you can't use the automated conversion tools... But even in that case, you can still create a Core ML model using NeuralNetworkBuilder (part of coremltools), but you'll have to do all of this by hand.

Related

How to do fine tuning on TFlite model

I would like to fine tune a model on my own data. However the model is distributed by tflite format. Is there anyway to extract the model architecture and parameters out of the tflite file?
One approach could be to convert the TFLite file to another format, and import into a deep learning framework that supports training.
Something like ONNX, using tflite2onnx, and then import into a framework of your choice. Not all frameworks can import from ONNX (e.g. PyTorch). I believe you can train with ONNXRuntime, and MXNet. Unsure if you can train using TensorFlow.
I'm not sure to understand what you need. But if you want to know the exact architecture of your model you can use neutron to find out.
You will get something like the this :
And for your information TensorFlow Lite is not meant to be finetuned. You need to finetune a classic TensorFlow model and then convert it to TensorFlow Lite.

How to run tensorflow 2.0 model inference in Java?

I have a Java application that use my old tensorflow models. I used to convert the .h5 weights and .json model into a frozen graph in .pb.
I used a similar code than in this github https://github.com/amir-abdi/keras_to_tensorflow.
But this code but it's not compatible with tf 2.0 model.
I couldn't find any other resources.
Is it even possible?
Thank you :)

Can you convert a .tflite model file to .coreml - or back to a Tensorflow .pb file or keras h5 file?

General question: is there tooling to convert from tflite format to any other format?
I'm trying to convert a keras model to a CoreML model, but I can't because the model uses a layer type unsupported by CoreML (Gaussian Noise). Converting the keras .h5 model to a .tflite is simple, removes the offending layer (which is only used in training anyway), and performs some other optimisations. But it doesn't seem possible to convert out of the resultant tflite to any other format. Coremltools doesn't support tflite. I thought I could probably load the model from tflite into a tensorflow session, save a .pb from there, and convert that to coreml using coremltools, but I can't see a way to load the tflite model into a tensorflow session. I saw the documentation linked to in this question, but that seems to use the tflite interpreter to read the tflite model, rather than a "true" Tensorflow session.

How to retrieve original TensorFlow frozen graph from .tflite?

Basically I am trying to use google's pre trained Speaker-id model for speaker detection. But this being a TensorFlow Lite model, I can't use it on my Linux pc. For that, I am trying to find a converter back to its frozen graph model.
Any help on this converter or any direct way to use tensorflow Lite pretrained models on desktop itself, will be appreciated.
You can use the converter which generates tflite models to convert it back to a .pb file if that is what you're searching for.
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/toco/g3doc/cmdline_examples.md

Can I run a model trained using tensorflow on mxnet?

I have models trained on tensorflow. Can I use mxnet in forward only mode to run these ?
https://github.com/dmlc/nnvm says this should be possible in future, but is the support available today ?
MXNet doesn't have tensorflow model converter yet. It does have a caffe-to-mxnet converter. So you can convert your tf model to caffe, that would work..
https://github.com/dmlc/mxnet/tree/master/tools/caffe_converter