Can I save python function as .tflite? - flutter

I want to preprocess an audio file and convert it to spectrogram before inserting it to my tflite model in flutter app. is there a way I can run my preprocessing function (.py) on flutter by converting it to .tflite?

That's currently not supported. You would have to include the preprocessing steps in the model itself (as TF ops, if the ops are supported in TFLite) so that it's included in converted TFLite model, or preprocess it manually outside the model in Flutter.
Kindly close the issue / mark this as the accepted answer if your issue is resolved.

Related

Flutter - Google ML kit - Text Recognition - Unable to read MRZ correctly

I am working on a flutter project wherein I need to read RMZ code from passport or ID cards.
I am using google ml kit's text recognition package (google_mlkit_text_recognition) to do this job and I am able to read the RMZ code.
The trouble is, the ml kit seems to gobble up a lot of '<'s from the RMZ code and also (only) sometimes seems to be able to convert the dates from 'YYMMDD' as in the passport RMZ to 'DD/MM/YYYY'.
Due to this inconsistency, I am unable to accurately get the required elements from the RMZ code.
Is there a way to make the ml kit simply read the code and spit it out as it is, in its raw form? Or is there some other way to do this - maybe use another plugin?
In case someone asks for the code. It's a boilerplate, see below:
final textDetector = TextRecognizer();
RecognizedText recognisedText = await textDetector.processImage(inputImage)
It would be helpful if you posted an image and the relative model output, pointing out what the model is failing at. Anyways, it seems weird the model does anything more to the output than giving you what it reads block by block. Having said this, the problem might be that the model is not suited for your specific task, in which case I would go on as follows:
Switch from your current model to the other available OCR model on Ml Kit. (eg. : from V2 beta to V1 or viceversa);
Try pre-trained models from Tensorlfow Hub;
Train a pre-trained model on your specific task;
Train a model from scratch on your specific task;
Look for any cloud based service which offer a model suited for your task;
This is everything I can come up with given the limited context of your question. If you are willing to expand on your specific problem I might be able to give you more precise info.

Darknet model to onnx

I am currently working with Darknet on Yolov4, with 1 class.
I need to export those weights to onnx format, for tensorRT inference.
I've tried multiple technics, using ultralytics to convert or going from tensorflow to onnx. But none seems to work. Is there a direct way to do it?
Check this GitHub repo: https://github.com/Tianxiaomo/pytorch-YOLOv4
Running the demo_darknet2onnx.py script you'll be able to generate the ONNX model from the .cfg and .weights darknet files.
Usage example:
python demo_darknet2onnx.py <cfgFile> <weightFile> <imageFile> <batchSize>
You can also decide the batch size for the inference calls of the converted model.
The following repo exports yolov3 models from darknet to onnx, for tensorRT inference. You can use this as reference for your model.
https://github.com/jkjung-avt/tensorrt_demos/tree/master/yolo
You can convert scaled YOLO-yolov4,yolov4-csp.yolov4x-mish,yolov4-P5 etc models into onxx & its perfectly work fine.
https://github.com/linghu8812/tensorrt_inference

Error library Simulink

I have created a simple Simulink library because I am learning about masks. The library is saved into Documents folder, which is in path of MATLAB. To test my library, I've created a model and I've inserted my block from my library. When I want to change the value of a parameter in the mask I receive this error screenshot of message
Is there any configuration to do?
Thank you so much

Suggestion to consider improving MatFile support by using code from csmatio to read and write .mat files

is anyone using MatFile classes in ilnumerics?
I just tried to open a MAT file created using csmatio and found I could not import it into ilnumerics application.
Hit throw new Exception("element data type is not supported");
as there is no support for mxSTRUCT_CLASS in the method
private ILBaseArray read_miMATRIX(BinaryReader br).
Is it a lot of work to add support for mxSTRUCT_CLASS?
ILNumerics will add support for HDF5 soon. This will also provide access to recent Matlab mat files. There are no plans to improve the old ILMatFile interface currently.

Using model callback with Simulink Coder

I am using Matlab 2012a and the Simulink Coder (aka Real-Time Workshop). I want to compile the model using Simulink Coder but preserve the functionality of model callbacks.
Consider the following simple example. I have a Simulink model, callBackTest, which reads in a constant and outputs to a since. input1 is defined in myValues.m and loaded into the model workspace using the PreLoadFcn model callback. The PreLoadFcn callback is executed when the model is first opened. By using the PreLoadFcn callback, input1 will automatically be defined every time the model is opened.
Suppose myValues.m is originally coded as input1=1. When you run the simulation, yout will be an array of 1s. Also if I compile the model using the Simulink coder, the output will also be an array of 1s. However if I modify myValues.m so that input1 = 2 and do not recompile, the realtime output is still 1. This is wrong, so how can I read variables from a file into the model workspace with a compiled model?
You cannot generate code for model callbacks. If you do not want to regenerate code every time you change your input you can try using "From File" block which can read data from a .mat file. When you want to change your data you can then run your MATLAB code and save the output data into the same .mat file. There are some restrictions on what kind of data is supported for code generation from this block. Check out the doc for that block for details.
If your data is not too big you can also edit the generated source to modify the data. Data from Constant block is usually in-lined in the generated source code. After editing you can compile the generated code to produce new binary.
Another approach is to write your custom C S-Function where you can read from your own data sources. You need to write a TLC file to support code generation for this S-Function.
You need to recompile your model if these does not work for you. Documentation at http://www.mathworks.com/help/simulink/ug/importing-signal-data-in-simulink.html lists different ways of importing signal data into Simulink.
This does not answer your question about Model callbacks, but it might be helpful anyway.
If the "Inline Parameters" option is checked in:
Preferences -> Optimization -> Signals and Parameters
there is no way to change values in an already compiled model because they are hardcoded. Once you have this option turned off and you have recompiled, you could for example connect with external mode and run your myValues.m script and the values will be updated (unless you have marked them as non-tuneable).