Is there method .predict in official python bindings for fastText - machine-learning

I know there are unofficial bindings with .predict method in python(fasttext, pyfasttext) but they do not work with recent models trained on on official FastText bash tool or do not have all the options. Official python bindings have only load_model(path)and tokenize(text) methods described , which sounds strange as with this you can not do any predictions. Am I missing something here?

I use the Python package built and installed according to this link https://github.com/facebookresearch/fastText/blob/master/README.md#building-fasttext-for-python. I consider it official.
The model object loaded via load_model has the requested predict method.

Related

What is the format of pytorch models?

I have to create a workflow that uses pytorch models or torch script models in c++. However, I can't find the binary format. I tried looking through the serializer but to no avail. Does anybody have documentation or code that gives me a clue as to the model format?
PyTorch has a great tutorial of Tracing/Scripting models and Loading them via C++.

How to convert pytorch model to TensorRT?

I have trained the classification model on Nvidia GPU and saved the model weights(checkpoint.pth). If I want to deploy this model in jetson nano and test it.
Should I convert it to TenorRT? How to convert it to TensorRT?
I am new to this. It would be helpful if someone can even correct me.
The best way to achieve the way is to export the Onnx model from Pytorch.
Next, use the TensorRT tool, trtexec, which is provided by the official Tensorrt package, to convert the TensorRT model from onnx model.
You can refer to this page: https://github.com/NVIDIA/TensorRT/blob/master/samples/opensource/trtexec/README.md
The TRTEXEC is a more native tool that you can take it from NVIDIA NGC images or downloading from the official website directly.
If you use a tool such as torch2trt, it is easy to encounter the operator issue and complicated to resolve it indeed (if you are not familiar to deal with plugin issues).
You can use this tool:
https://github.com/NVIDIA-AI-IOT/torch2trt
Here are more details how to implent a converter to a engine file:
https://github.com/NVIDIA-AI-IOT/torch2trt/issues/254

What is the relationship between PyTorch and Torch?

There are two PyTorch repositories :
https://github.com/hughperkins/pytorch
https://github.com/pytorch/pytorch
The first clearly requires Torch and lua and is a wrapper, but the second doesn't make any reference to the Torch project except with its name.
How is it related to the Lua Torch?
Here a short comparison on pytorch and torch.
Torch:
A Tensor library like numpy, unlike numpy it has strong GPU support.
Lua is a wrapper for Torch (Yes! you need to have a good understanding of Lua), and for that you will need LuaRocks package manager.
PyTorch:
No need for the LuaRocks package manager, no need to write code in Lua. And because we are using Python, we can develop Deep Learning models with utmost flexibility. We can also exploit major Python packages likes scipy, numpy, matplotlib and Cython with PyTorch's own autograd.
There is a detailed discussion on this on pytorch forum. Adding to that both PyTorch and Torch use THNN. Torch provides lua wrappers to the THNN library while Pytorch provides Python wrappers for the same.
PyTorch's recurrent nets, weight sharing and memory usage with the flexibility of interfacing with C, and the current speed of Torch.
For more insights, have a look at this discussion session here.
Just to clarify the confusion between both pytorch repositories:
pytorch/pytorch is very similar to (Lua) Torch but in Python. So it's a wrapper over THNN. This was written by Facebook too.
hughperkins/pytorch: I have come across this repo when I was developing in Torch before pytorch existed, but I have never used it so I'm not quite sure if it is a wrapper written in Python over (Lua) Torch which is in turn a wrapper over THNN OR a wrapper over THNN and Lua. In both case, this is not the original version of Torch. It was written by Hugh Perkins when there was no Python alternative for Torch.
If you are wondering which one to go for, I would definitely recommend pytorch/pytorch as it communicates directly with THNN, is written by the people who made THNN and is continuously maintained. hughperkins/pytorch does not seem to be maintained anymore.

Convert .pb file (Tensorflow model file) to human readable format

I am new to tensorflow. I have downloaded and run the image classifier provided on tensorflow website. I can see link that downloads model from web.
I have to read the .pb file in human readable format.
Is this possible? if yes, How?
Thanks!
If you mean the model architecture then I recommend looking at the graph in Tensorboard, the graph visualisation tool provided with Tensorflow. I'm pretty sure that the demo code/tutorial already implements all the code required to import into tensorboard so it should just be a case or running tensorboard and pointing it to the log directory. (This should be defined in the code near the top).
Then run tensorboard --logdir=/path/to/logs/ and click the graphs tab. You will then see the various graphs for the different runs.
Alternatively, there are a couple of papers on inception that describe the model and the theory behind it. One is available here
Hope that helps you understand inception a bit more.

How do I create a custom haar classifier?

I am struggling to create a custom haar classifier. I have found a couple tutorials on the web, but they do not specify which version of opencv they are using. What I need is a very concise and simplified example of the steps that are required, along with a simple dataset of images. I also need to know the opencv version and the OS platform so I can get it running. I have tried a matrix of opencv versions on both windows and linux and I have run into memory error after memory error. I would like to start with a known good set of data and simple commands before expanding it to fit my problem.
Thanks for your help,
Chris
OpenCV provides two utility commands createsamples.exe and haartraining.exe, which can generate xml files used by Haar Classifiers. That is, with the xml file outputted from haartraining.exe, you can directly use the face detection sample with your xml file to detect any customized objects.
About the detailed procedures to use the commands, you may consult Page 513-516 in the book "Learning OpenCV", or this tutorial.
About the internal mechanism of how the classifier works, you may consult the paper "Rapid Object Detection using a Boosted Cascade of Simple
Features", which has been cited 5500+ times.

Resources