Convert torch model (torch.save) into matricial formulas that can be handled with basic Python - numpy

Please could you tell me if it is feasible to transform a torch model (torch.save) into algebraic matrices/ equations that can be operated with numpy or basic Python, without the need to install torch and other related libraries (that occupy a lot of space)? In an afirmative case, could you please give me some hints or a link with explanations? Thank you very much.

I'm not aware of any way to do this without a lot of your own work. Basically you'd have to port most of the pytorch library to numpy, which would be a huge project. If space is an issue check if you can save some space by e.g using earlier torch versions or using only the CPU-versions of pytorch.

Related

Freeze Saved_Model.pb created from converted Keras H5 model

I am currently trying to train a custom model for use in Unity (Barracuda) for object detection and I am struggling near what I believe to be the last part of the pipeline. Following various tutorials and git-repos I have done the following...
Using Darknet, I have trained a custom-model using the Tiny-Yolov2 model. (model tested successfully on a webcam python script)
I have taken the final weights from that training and converted them
to a Keras (h5) file. (model tested successfully on a webcam python
script)
From Keras, I then use tf.save_model to turn it into a
save_model.pd.
From save_model.pd I then convert it using tf2onnx.convert to change
it to an onnx file.
Supposedly from there it can then work in one of a few Unity sample
projects...
...however, this project fails to read in the Unity Sample projects I've tried to use. From various posts it seems that I may need to use a 'frozen' save_model.pd before converting it to ONNX. However all the guides and python functions that seem to be used for freezing save_models require a lot more arguments than I have awareness of or data for after going through so many systems. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py - for example, after converting into Keras, I only get left with a h5 file, with no knowledge of what an input_graph_def, or output_node_names might refer to.
Additionally, for whatever reason, I cannot find any TF version (1 or 2) that can successfully run this python script using 'from tensorflow.python.checkpoint import checkpoint_management' it genuinely seems like it not longer exists.
I am not sure why I am going through all of these conversions and steps but every attempt to find a cleaner process between training and unity seemed to lead only to dead ends.
Any help or guidance on this topic would be sincerely appreciated, thank you.

I want to use hidden markov model for data prediction

I am new to machine learning models and data science libraries. I wanted to use the Hidden Markov model for statistical data prediction on the fly which read the data from kafka and builds the model which is used to predict the data during the run-time and do the same for continous stream always.
Currently i can see only Tensorflow hidden markov model implementation in tensorflow python (tensorflow_probability distribution). Is their any other library available which can help me acheive the above scenario
Suggestions can involve the libraries of JAVA and python
Please feel free to add any resource links that can help me to understand the usage of tensorflow for hidden markov model
this might be a nice place to start: https://hmmlearn.readthedocs.io/en/latest/tutorial.html
Other alternatives, I found, are
Java:
Mallet library and it's extention GRMM in particular.
Python:
Pommegranate with it's HMM support.
Having said that, TensorFlow is much better known active and supported library, in my impression. I'd try that first.
I'm searching a library that would support Hierarchical HMMs (HHMM). That would probably require some tweaking into one of the listed ones.

Performance drawback of tf.numpy_function?

I'm using a tf.numpy_function to load a file in my tensorflow program.
I can't find sufficient information about the drawbacks of using numpy_function, would there be enough that it's worth the trouble of passing this function to tensorflow compatible code ?
Thanks a lot

Numerically Stable Tensorflow

Tensorflow has been used to compute images but I want to use Tensorflow to compute Biological Models. However, the biological model requires big division and this causes numerical instability. I want to have TensorFlow that supports more numerically stability. Are there any hacks to allow Tensorflow to be more numerically stable? I will follow up with more codes in the near feature but if there are any options please tell me.
Please refer to the below paper on Tensorflow Distributions and see if it helps answer your question.
https://arxiv.org/pdf/1711.10604.pdf
If not, please elaborate your issue.
Mention any code snippet of what you have tried, or any limitations you faced while implementing your model.

tensorflow embedding projector t-sne algorithm difference from other implementation?

I've been playing with the tensorflow standalone embedding projector (http://projector.tensorflow.org/) and found it a very helpful tool for visualization. However, when I try to replicate the t-sne result using other implementations (e.g., Rtsne, sklearn.manifold.tsne), the low dimension projection seems to be very different. Particularly, the clusters are much more spread-out in the embedding projector than that learnt using R or python packages.
I used the same perplexity, learning rate and momentum parameters. And tried both spherizing or not spherizing the data as implied in the projector.
Could anyone help to shed light on the difference between the tensorflow projector implementation of the t-sne algorithm and other implementations like Rtsne? For example, is there a similar 'exaggeration' parameter used in the projector as in Rtsne? What is the optimization algorithm? Or is there anything special in generating the visualization?
I believe the source code of the tensorflow projector is the oss_demo_bin.js file in https://github.com/tensorflow/embedding-projector-standalone. Unfortunately I'm not familiar with javascript and found it hard to interpret.
Thanks!